tags:

views:

127

answers:

2

What is a good way of using PHP with nginx? From the finding I got, maybe using PHP-FPM might be a good way of handing PHP behind nginx.

The problem we have is that the free web based API we serve gets a lot of request (about 500K a day), mostly the requests are very short and small in size but Apache is consuming a lot of memory. I want to try nginx to see if it can handle it better.

Thanks

A: 

Here is the link where you can setup nginx + php-fpm + apc http://interfacelab.com/nginx-php-fpm-apc-awesome/

In my opinion, use php + lighttpd to handle that request. Lighttpd is the the best webserver to handle many request with only require small memory. After then point your nginx proxy to where lighttpd listen.

+2  A: 
  1. Ubuntu Lucid 64-bit
  2. apt-get install nginx
  3. apt-get update
  4. apt-get install php5-cli php5-common php5-suhosin
  5. apt-get install python-software-properties
  6. add-apt-repository ppa:brianmercer/php
  7. apt-get update && apt-get install php5-fpm php5-cgi
  8. /etc/init.d/nginx restart
  9. /etc/init.d/php5-fpm restart

Edit (might need this in your site conf) :

    location ~ \.php$ {
        fastcgi_read_timeout 60000;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /var/www/site$fastcgi_script_name;
        include         fastcgi_params;
    }
    location ~ /\.ht {
            deny  all;
    }
Orbit