Isaac Sloan - Running php on an ngnix server set up for Rails.

Running php on an ngnix server set up for Rails.

Its super easy to set up a server for php if you're running apache as your default web sever. However, I recently had to figure out the how to run php an Ubuntu server which has been set up for rails using nginx and passenger. One option is to run apache on a different port and then route that through nginx but this method requires a lot of memory. The solution I choose was to use php-fpm.

apt-get install php5-fpm

In your /etc/php5/fpm/pool.d/www.conf file make sure that listen is set to:

listen = 

Then set up your server config for whatever site is using php like this:

server {
        listen 80;
        index index.html;
        root /var/www/[site_name];
        location ~* \.php$ {
            fastcgi_index   index.php;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

And that's about it. Good luck.

UPDATE: If you need to send mail should use postfix instead of sendmail as php-fpm has a weird infinite loop bug with sendmail.

December 05, 2012
comments powered by Disqus