DISQUS

interfacelab: NGINX + PHP-FPM + APC = Awesome

  • jc00ke · 8 months ago
    I had looked into using the Lighty spawner for a project but I like this method much better.
  • Owen · 8 months ago
    the section about the init script seems to be a cut and paste error... the contents shown are actually the default site config.
  • jawngee · 8 months ago
    Thanks for the heads up!

    Fixed now.
  • Jason Cianchette · 8 months ago
    Thanks for the post. I am in the process of making a similar transition and was considering Lighttpd + PHP + Xcache. Did you look into that configuration? If so do you have any thoughts about it?
  • James Moss · 8 months ago
    Do you have any numbers to show how much faster this method is compared to a normal apache/mod_php setup?
  • Derek Anderson · 8 months ago
    While I am currently deploying EXACTLY the config shown in the demo, I would like to point out that the problems it solves are NOT exactly what you might expect.
    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.
  • Mark · 8 months ago
    Does the fact that the PHP-FPM author has not updated the package since 13 December and that it still does not support PHP 5.2.9, worry you at all? (he's also been awol from their mailing list from what I can tell too). Yes, it's free and open source, so he's not obliged to maintain it of course. It's a promising piece of software, but it's a patch for PHP and is therefore tightly coupled with the PHP version (unlike Spawn-FCGI). It's one of the main things holding us back from using it.
  • nick · 1 month ago
    I think the intention is to bake FPM into PHP 6
  • Michał Bialik · 8 months ago
    You have a small mistake in last paragraph - instead of : "sudo php-fm" start should be "sudo php-fpm start" - by the way thank you very much for this guide - it saved me a lot of time.
  • David Rivers · 7 months ago
    I'm using your settings, but I keep getting "No input file specified."!!! Aaaaaahhhhh!!!!
  • iflyhigh · 7 months ago
    Give me a few hours, I have the solution for that particular problem.
  • Stewart Matheson · 5 months ago
    hey did you manage to find the solution to this? I am getting the same issue. Love the tute btw
  • Phil · 2 months ago
    I had this problem a few times and it was a path problem, make sure your site path in sites-enabled/default.conf is correct
  • Alexander · 1 month ago
    Use this to fix "No input file specified":
    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.
  • Charles · 7 months ago
    One more thing to speed up PHP

    ./configure --with-zend-vm=GOTO
  • Ben · 7 months ago
    Unless I missed something I had to change the extensions directory to :
    "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
    in php.ini to get apc working.
  • Philip Harrison · 7 months ago
    so I'm not at all experienced with this kind of stuff, but I was wondering if anyone has managed to install concrete5 cms using these settings?
    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 … ?
  • Steven Vo · 7 months ago
    1 typo in "Start It Up" part:

    1. sudo php-fpm start
  • Steven Vo · 7 months ago
    and should add in --with-mysql during the configure step of php installation as well.
    I encounter MySQL is not supported error now :(
  • Barry Fisher · 5 months ago
    I found that you need to install the source (dev?) MySQL client library for --with-mysql to work.
    # apt-get install libmysqlclient15-dev
  • Aco · 4 months ago
    thanks so much for that... this drove me insane... =)
  • Steven Vo · 7 months ago
    I've encounter duplicated value of PHP_SELF for example:
    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;
    }
  • me · 7 months ago
    I see you are using nginx/0.7.58 for this blog. But... your blog run slowly, like all others wordpress.
    So... with the same results, you can use apache.
    nginx and/or lighttpd are great for MMORPG or really high traffic websites
  • ceejayoz · 7 months ago
    Site works fine here, as do plenty of other WordPress sites.
  • iflyhigh · 6 months ago
    This site is actually run on a crappy $10 a month hosting joint.

    Check out http://massify.com/ which is what the article is based on.
  • ahto111 · 6 months ago
    Have you tried nginx-ey-balancer, could it give a boost to this configuration?
  • iflyhigh · 6 months ago
    No, I didn't even know it existed until you pointed it out. Will check it out, thanks for the heads up!
  • Alex · 5 months ago
    One article how to install nginx you can find on the http://www.linuxspace.org/archives/1576

    I used it for my site, cuz I use ubuntu server
  • luka · 5 months ago
    Can be latest version of php be used instead this version in this tutorial?
  • Stewart Matheson · 5 months ago
    Hey great tute but i am getting no input file in my browser when i browse to my site with an index.php and a phpinfo call in that file. Is there simple solution for this?
  • Vito Botta · 5 months ago
    Hi, first of all many thanks for this guid. I have a similar setup mostly thanks to this guide.
    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.
  • Ivo · 2 months ago
    APC!? Screw that, give memcached a try!!!
  • vonchuckles · 2 months ago
    @Ivo: APC and memcached are tools for different purposes.

    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.
  • salexiev · 1 month ago
    what about with-gd?
  • stame · 1 week ago
    I follow the tutorial on Ununtu 8.04, and php configuration says this at the end:

    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.
  • stame · 1 week ago
    Solved. Forgot that we are only processing index.php and not *.php:

    location ~ ^/index.php
  • stame · 1 week ago
    So... it is working, but these unknown configuration options disturb me. Why are they unknown, and will I need them? I will try to use pfp-fpm with Drupal.
  • stame · 1 week ago
    I used php-5.2.11 and php-fpm-0.6~5.2.11