Home   >>   Nginx   >>   How To Install Nginx With PHP 5.3 And PHP-FPM Support On CentOS 6
How To Install Nginx With PHP 5.3 And PHP-FPM Support On CentOS 6 PDF Print E-mail
( 1 Vote )
How To - Nginx
Written by Christian Foronda   
Wednesday, 20 July 2011 19:08

This tutorial is tested only on CentOS 6.0 but might also work on future CentOS 6 versions.

This is done on a bare install of CentOS 6.

 

Update your packages:

# yum -y update

 

Install the repo that we will use to download nginx:

For i386 architecture:

# rpm -ivh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm

For x86_64 architecture:

# rpm -ivh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm

 

Install the repo that we will use to download php-fpm:

# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

 

Enable the remi repository:

# vi /etc/yum.repos.d/remi.repo

 

On line 5, change the 0 to 1:

enabled=1

 

Install nginx:

# yum -y install nginx

 

Install PHP5 and php-fpm:

# yum -y install php php-mysql php-fpm php-suhosin

 

Now, disable again the remi repository. We don't want the repo to replace our core packages:

# vi /etc/yum.repos.d/remi.repo

 

On line 5, return the 1 to 0:

enabled=0

 

Remove Apache since we will use Nginx:

# rpm -e --nodeps httpd

 

Configure nginx:

# vi /etc/nginx/nginx.conf

 

On line 101, uncomment the following:

location ~ \.php$ {
	root           html;
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
	include        fastcgi_params;
}

 

On line 105, change the line with the one below:

fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;

 

Start nginx and php5-fpm:

# chkconfig nginx on
# /etc/init.d/nginx start
# chkconfig php-fpm on
# /etc/init.d/php-fpm start

 

Create phpinfo script to access it from your browser:

# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/x.php

 

Go to your browser and access:

http://localhost/x.php


Restarting php5-fpm is necessary only if you changed something on your php.ini. Restarting nginx isn't' necessary.




blog comments powered by Disqus
Last Updated on Friday, 22 July 2011 08:22