Share Coding

Tutorials, Problems, Stuffs …

Install Nginx + PHP + MySQL on CentOS

1. Install EPEL & RPMI & YUM-Priorities

rpm -Uvh
rpm -ivh
yum install yum-priorities

2. Update OS

yum update

3. Edit EPEL repo: Add “priority=10” under “enabled=1

vi /etc/yum.repos.d/epel.repo

name=Extra Packages for Enterprise Linux 6 - $basearch

4. Edit RPMI repo: Add “priority=10” under “enabled=0” and change “enabled=0” to “enabled=1

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

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

5. Install Nginx & PHP & MySQL

yum install php php-devel php-fpm php-cli php-mysql php-gd php-imap php-xml php-xmlrpc php-mbstring php-mcrypt php-pear php-common php-pear-Mail php-pear-Net-Socket php-pdo php-pear-Auth-SASL php-pear-Net-SMTP php-eaccelerator mysql mysql-server nginx

6. Config PHP-fpm: Change listen to “/tmp/php5-fpm.sock

vi /etc/php-fpm.d/www.conf

;listen =
listen = /tmp/php5-fpm.sock

7. Test Service

service mysqld restart
service php-fpm restart
service nginx restart

8. Config MySQL password

mysqladmin -u root password yourPassword

9. Change PHP Session permission

chmod -c 777 -R /var/lib/php/session/

10. Close firewall

vi /etc/sysconfig/selinux


> Firewall Configuration
> Customize
> Enable www

11. Reboot and Start Server

service mysqld restart
service php-fpm restart
service nginx restart

12. You can change the setting of Nginx on /etc/nginx/conf.d/default.conf

location ~ \.php$ {
	root           /usr/share/nginx/html;
	try_files $uri =404;
	fastcgi_pass   unix:/tmp/php5-fpm.sock;
	fastcgi_index  index.php;
	fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	include        fastcgi_params;

13. Change the permission of php-fpm.sock

chmod -c 777 -R /tmp/php5-fpm.sock

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: