Home » Php » How to use nginx with PHP?

How to use nginx with PHP?

Posted by: admin July 12, 2020 Leave a comment

Questions:

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), the requests are mostly 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.

How to&Answers:
  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;
    }