The following describes how to install and configure nginx + MySQL + PHP-FPM:
1. Change source, update:
# rpm -Uvh http://centos.alt.ru/repository/centos/6/i386/centalt-release-6-1.noarch.rpm# yum update
2. Install nginx + MySQL + PHP-FPM:
# yum install nginx-stable php-fpm mysql-server php-mysql mysql-server php-mbstring php-gd php-pear php-mcrypt php-mhash php-eaccelerator -y
3. Set the MySQL password and start MySQL, nginx, and PHP-FPM at startup:
# Service mysqld start # mysqladmin-u Root Password 'Password' # chkconfig nginx on # chkconfig mysqld on # chkconfig PHP-FPM on
Note: The following error occurs when PHP-FPM is started by default:
Starting PHP-FPM: [28-nov-2011 08:11:01] error: [pool WWW] cannot get uid for user 'apache'
Solution:
# vi /etc/php-fpm.d/www.conf
Find the following two rows:
user = apachegroup = apache
Change Apache to nginx.
4. enable port 80 (disabled by default ):
# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT# /etc/rc.d/init.d/iptables save# /etc/init.d/iptables restart
5. Modify the nginx configuration file and start nginx and PHP-FPM:
# vi /etc/nginx/nginx.conf
Change the root directory of the website and add the default PHP file:
location / {root /usr/share/nginx/html;index index.php index.html index.htm;}
Modify the code to add PHP support:
# location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;# include fastcgi_params;#}
Delete all the above # And one line (in blue), and modify the website directory to be consistent with the previous one. Start nginx and PHP-FPM:
# service nginx start# service php-fpm start