-
Website
http://interfacelab.com -
Original page
http://interfacelab.com/nginx-php-fpm-apc-awesome/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
Evan Courtney
1 comment · 1 points
-
smikolay
1 comment · 1 points
-
sparkletack
4 comments · 1 points
-
Andlil
1 comment · 1 points
-
rryan
1 comment · 1 points
-
-
Popular Threads
Fixed now.
Apache has 2 major problems when serving PHP.
1: Holy memory usage batman! Apache forks a new process for each PHP script running, and can easily eat a HUGE amount of ram
2: Slow clients will cause those processes to be held up, using all that ram, while the process serves the data to the client.
By placing Nginx in front of PHP-FCGI, you are causing the page to render, then disconnect from the PHP process while Nginx serves the actual data. This means you can have fewer PHP processes, and in turn they use less ram. Tuning your fcgi buffers settings on Nginx can be important here, make sure it is big enough for most of your pages to cache in ram.
An equally good solution is to place Nginx with a lot of big proxy buffers in front of an Apache server running a smaller # of maxclients. Also be sure to configure Nginx to handle static files directly. This is the best of both worlds, and we have seen much higher page throughputs with this config.
location ~ .php$ {
fastcgi_param SCRIPT_FILENAME /path/to/root/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
And restart nginx.
./configure --with-zend-vm=GOTO
"/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
in php.ini to get apc working.
I managed to get to the point where the installer shows green checks across the board, but whe I try to istall it just halts half way and shows a blank page with a half full db…? managed to get wordpress going though.
concrete5: http://www.concrete5.org/
my site: http://67.23.25.191/
php info: http://67.23.25.191/index.html
and btw, what if I have a php file that isn't called index.php, how do I load it? like a simple script that resides either in the same folder as index.php or a subfolder … ?
1. sudo php-fpm start
I encounter MySQL is not supported error now :(
# apt-get install libmysqlclient15-dev
this php code
print $_SERVER['PHP_SELF'];
willl produce
test.php/test.php
To fix, comment off the line 26 in your file /etc/sites/default.conf:
# if the request starts with our frontcontroller, pass it on to fastcgi
location ~ ^/index.php
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/default/pub$fastcgi_script_name;
# fastcgi_param PATH_INFO $fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
So... with the same results, you can use apache.
nginx and/or lighttpd are great for MMORPG or really high traffic websites
Check out http://massify.com/ which is what the article is based on.
I used it for my site, cuz I use ubuntu server
One problem I am still having after a while, though, is that all the php-cgi processes die after a while the server has been in idle (I am working on a blog with no traffic yet other than mine) and no new ones are automatically started as soon as a new request is made through nginx. The result is that nginx will return a nice "502/bad gateway" until
I manually run "php-fpm start" :-(
Does anybody know a way to make this stuff automatic?
Thanks in advance.
ps: you might want to add an init.d script to your guide, to automatically start php-fpm at boot time.
APC contains a memory-backed data cache feature (which is what memcached is), however that is not its primary purpose-- its just an add-on. It's real purpose is to cache the interpreted versions of the scripts used in the site, in memory. This can increase execution speed of PHP scripts for most sites by 200% to 1000% or more. Memcached cannot do this. If you're running a PHP-heavy site and not using APC, you're wasting insane amounts of CPU cycles. There may be some obscure exceptions, but so far I have yet to see an example where APC doesn't provide a drastic speedup.
You'll notice in the instructions however that he does install the memcache PECL extension as well, meaning that he already does (probably) use memcache for data storage, but uses APC for its (intended) opcode caching purpose.
Notice: Following unknown configure options were used:
--enable-fpm
--enable-pic
--with-xml
--enable-xslt
--enable-memcache
Check './configure --help' for available options
Finally, when I complete everything, php files are not processed, the browser just wants to download them. Anyone has any idea?
Great tutorial, by the way.
location ~ ^/index.php