First, Nginx installation
1. View the Yum Nginx version information
[email protected] ~]# Yum List | grep nginx
2. Manually add Nginx's Yum repository
[Email protected] ~]# Vi/etc/yum.repos.d/nginx.repo
The added content is:
[Nginx] Name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0 enabled=1
3. Edit save before viewing Nginx version:
4. Install Nginx Service:
[email protected] ~]# Yum install-y nginx
5. Start the Nginx service:
[[Email protected] ~]# service Nginx start
Note:/etc/nginx/nginx.conf # nginx configuration file location
6. Set Boot up
[[email protected] ~]# chkconfig nginx on
7.nginx Service Restart:
[Email protected] ~]#/etc/init.d/nginx restart
8. Test is normal:
[[email protected] ~]# Curl http://127.0.0.1
9. Delete the default test page:
[Email protected] ~]# RM-RF /usr/share/nginx/html/*
Second, install MySQL
1. Install MySQL
2. Start MySQL
[[email protected] ~]#/etc/init.d/mysqld start
3. Set Boot up
4. Set the password for root:
[Email protected] ~]# mysql_secure_installation
5. Restart the MySQL service:
[[email protected] ~]#/etc/init.d/mysqld stop #停止 [[email protected] ~]#/etc/init.d/mysqld start #启动 [email Protected] ~]# service mysqld restart #重启
6. Set allow remote connection to MySQL
[[email protected] ~]# mysql-u root-pmysql>use MySQL; Mysql>grant all privileges on * * to ' root ' @ '% ' identified by ' 123456 ' with GRANT option; [Email protected] ~]# service mysqld restart #重启
Third, install PHP
1. Install PHP
[[email protected] ~]# Yum install php- y
2. Install PHP components to enable PHP support for MySQL, PHP support fastcgi mode
[email protected] ~]# Yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc PHP-MB String Php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm
3. Restart MySQL
4. Restart Nginx
/etc/init.d/nginx Restart
5. Start PHP-FPM
/ETC/RC.D/INIT.D/PHP-FPM start
6. Set Boot PHP-FPM
Chkconfig PHP-FPM on
Iv. Configuration of Nginx support PHP
1. Back up the original configuration file
cp/etc/nginx/nginx.conf /etc/nginx/nginx.confbak
2. Edit the configuration file
Vim /etc/nginx/nginx.conf user nginx nginx ; #修改nginx运行账号为: Nginx User of Nginx group: wq! #保存退出
3. Back up the original default configuration file
4. Edit the default configuration
Vim/etc/nginx/conf.d/default.conf
Fix the content as:
Index index.php index.html index.htm; #增加index. php
Modify to the following content:
# Pass the phpscripts to FastCGI server listening in 127.0.0.1:9000 # location ~ \.php$ { root html; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params;} #取消FastCGI the comment for the server section location, and note the parameters of the Fastcgi_param row, change to $document_root$fastcgi_script_name, or use the absolute path
V. Configuration of PHP
1. Configuration files
Vim/etc/php.ini #disable_functions =passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec #在386行 List PHP can disable dangerous function #expose_php = Off #在432行 Suppress the PHP version of the information #magic_quotes_gpc = on #在745行 Open Magic_quotes_ GPC to prevent SQL injection
Six, configuration php-fpm
1. Back up the original configuration file
cp/etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak
2. Edit the configuration file
Vim/etc/php-fpm.d/www.conf
Modify to the following:
user = Nginx = Nginx #修改组为nginx
3. Restart MySQL
/etc/init.d/mysqld Restart
4. Restart Nginx
/etc/init.d/nginx restart
5. Restart PHP-FPM
/ETC/RC.D/INIT.D/PHP-FPM Restart
Summary: The NGNIX+PHP+MYSQL application has been successfully built up in CentOS!
Install Ngnix+php+mysql service under CentOS