Setting up Nginx + php-fcgi
I assume nginx is already installed. What’s left is to set up php handling. Everything below was done on CentOS Linux. You can repeat the same steps on Linux Ubuntu with minor changes.
For CentOS you need to add the Epel repository:
Centos 5.x:
rpm -Uvh http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Centos 6.x:
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Next, install the needed packages:
yum install php-fastcgi
Download the needed files:
cd /etc/init.d/
wget https://gist.github.com/raw/1032914/gistfile1.sh -O php-fastcgi
wget https://gist.github.com/raw/1035180/gistfile1.sh -O php-fpm-nginx.conf
Make them executable:
chmod +x php-fastcgi
Enable autostart and start the service:
chkconfig php-fastcgi on
service php-fastcgi start
Check:
netstat -tulpn |grep 9000
Next, configure Nginx:
Add the following lines to the host config in nginx:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Restart nginx.