Installing Nginx width php5 and mysql support on centos 6.4

Nginx (pronounced engine-x) is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18% (22.2M) of active sites across all domains. Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

In this tutorial I use the hostname srv1.lintut.com with the IP address These settings might differ for you, so you have to replace them where appropriate.
First enable EPEL and remi repository.

Install yum priorities

# yum install yum-priorities

Edit /etc/yum.repos.d/epel.repo and add the line priority=10 to the [epel] section:

name=Extra Packages for Enterprise Linux 6 - $basearch

Edit /etc/yum.repos.d/remi.repo and change enabled to 1 and add priority=10:

nano /etc/yum.repos.d/remi.repo
name=Les RPM de remi pour Enterprise Linux $releasever - $basearch

name=Les RPM de remi en test pour Enterprise Linux $releasever - $basearch

Installing Nginx

Nginx is available as a package for CentOS 6.4 (from EPEL) which we can install as follows:

yum install nginx

Start nginx and make it to start automatically on every reboot.

/etc/init.d/nginx start
chkconfig nginx on

Type in your web server’s IP address or hostname into a browser, and you should see the nginx welcome page:

Nginx welcome page
Nginx welcome page

Install MySql server

yum install mysql mysql-server -y
Install mysql server
Install mysql server

Set MySQL root password

Type next command and follow instruction:

Set mysql default password
Set mysql default password

Installing PHP5

We can make PHP5 work in nginx through PHP-FPM (PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites). We can install php-fpm together with php-cli and some PHP5 modules like php-mysql which you need if you want to use MySQL from your PHP scripts as follows:

yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It’s similar to other PHP opcode cachers, such as eAccelerator and Xcache. It is strongly recommended to have one of these installed to speed up your PHP page.
APC can be installed as follows:

yum install php-pecl-apc

Then open /etc/php.ini and set cgi.fix_pathinfo=0:

nano /etc/php.ini
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo

Start php-fpm service and configure to start automaticly on system boot:

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

Restart ngnix server

/etc/init.d/nginx reload

Testing PHP

Create test php page:

nano /usr/share/nginx/html/info.php

and paste following code:

Now we call that file in a browser (e.g.

Php info page
Php info page
php MySql module
php MySql module

Reference:unixmen.com and howtoforge.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.