Easy Steps for setting up nginx with php on Linux

I am using Fedora 10 so for that linux version i used these commands for setting up my server.

Installing Nginx:
yum install nginx

Then we create the system startup links for nginx:
/sbin/chkconfig –level 35 nginx on

We can make PHP5 work in nginx through FastCGI.For that install all this packages:
yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy

Then open /etc/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:
vi /etc/php.ini
paste this line :- cgi.fix_pathinfo = 1

To start a PHP FastCGI daemon listening on port 9000 on localhost and running as the user and group nginx, we run the following command:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

To restart PHP FastCGI daemon, Use this command:
ps -ef|grep php-cgi
kill PROCESS_ID

you don’t want to type in that command manually whenever you boot the system, so to have the system execute the command automatically at boot time, open /etc/rc.local…
vi /etc/rc.local
and add the command at the end of the file:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx  -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

THEN STOP THE APACHE WEB SERVER:
/sbin/init.d/httpd stop
To stop apache on every startup:
/sbin/chkconfig –level 35 httpd off

First take backup of your nginx configuration file:
cp /etc/nginx/nginx.conf nginx.conf_cp
use nginx.conf file from life180 “config/nginx” folder

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.