Share Coding

Tutorials, Problems, Stuffs …

Install Nginx + PHP + MySQL on CentOS

1. Install EPEL & RPMI & YUM-Priorities

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
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

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
priority=10

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

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

[remi]
name=Les RPM de remi pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
priority=10

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 = 127.0.0.1:9000
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

SELINUX=disabled
LANG=C
setup

> Firewall Configuration
> Customize
> Enable www

11. Reboot and Start Server

reboot
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
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: