This is a post on how to set up Nginx with PHP using spawn-fcgi on CentOS 6.
If you haven’t already done it, you have to set up the EPEL repository.
Next install Nginx and spawn-fcgi, I assume you have already installed PHP and all the modules you need.
Now it’s time for the spawn-fcgi configuration. The config should be at /etc/sysconfig/spawn-fcgi.
It’s very important that you remember the port, you’ll have to set the same in the nginx configuration. You should also use the same username and group as nginx.
To play it safe, make sure the following line is not commented in the file /etc/init.d/spawn-fcgi:
Now let’s make sure that spawn-fcgi and nginx automatically start after a reboot.
For more information about chkconfig check this site: http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-services-chkconfig.html
Next up we have to fix a folder permission. The group of the session cookies folder, the address can be found in the php.ini (session.save_path = “/var/lib/php/session”). The folder group has to be changed from apache to whatever you use, e. g. nginx. You should check this after every php update.
As a last step, just add the following line to the /etc/nginx.conf and/or your custom domain configuration in /etc/nginx/conf.d/yourdomain.conf.
You should also make some additional changes in your configuration. I’m going to make another post about some of the settings.
The official wiki is always a good source for help: http://wiki.nginx.org/Configuration