Preparation
1. Configure the firewall and enable ports 80 and 3306
[Root @ localhost ~] # Vim/etc/sysconfig/iptables
-A input-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT
[Root @ localhost ~] #/Etc/init. d/iptables restart firewall to make the configuration take effect
2. Disable SELINUX
[Root @ localhost ~] # Vim/etc/selinux/config
SELINUX = disabled
[Root @ localhost ~] # Reboot
3. Configure the centos third-party yum source (no nginx package exists in the standard source of centos by default)
[Root @ localhost ~] # Yum-y install wget install and Download wget tool
[Root @ localhost ~] # Wget http://www.atomicorp.com/installers/atomic download atomic yum source
[Root @ localhost ~] # Sh./atomic Installation
[Root @ localhost ~] # Yum check-update yum software package
Installation
1. Install nginx
[Root @ localhost ~] # Yum-y install nginx software
[Root @ localhost ~] # Start service nginx start
[Root @ localhost ~] # Chkconfig nginx on set startup
[Root @ localhost ~] #/Etc/init. d/nginx restart nginx service
[Root @ localhost ~] # Rm-rf/usr/share/nginx/html/* delete the default nginx page
2. Install mysql
[Root @ localhost ~] # Yum install mysql-server-y install mysql
[Root @ localhost ~] #/Etc/init. d/mysqld start mysql
[Root @ localhost ~] # Chkconfig mysqld on set startup
[Root @ localhost ~] # Cp/usr/share/mysql/my-medium.cnf/etc/my. cnf copy the configuration file, directly overwrite the original
[Root @ localhost ~] # Reboot restart system
[Root @ localhost ~] # Mysql_secure_installation set the password for the root user
[Root @ localhost ~] #/Etc/init. d/mysqld stop start mysql
[Root @ localhost ~] #/Etc/init. d/mysqld start stop mysql
[Root @ localhost ~] # Service mysqld restart mysql
3. Install php
[Root @ localhost ~] # Yum install php-y
[Root @ localhost ~] # Yum-y install php-mysql phpgd libjpeg * php-imap php-ldap php-odbc php-pear php-xml php xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt-devel php-fpm
[Root @ localhost ~] #/Etc/init. d/mysqld restart mysql service
[Root @ localhost ~] #/Etc/init. d/nginx restart nginx service
[Root @ localhost ~] #/Etc/rc. d/init. d/php-fpm start the php-fpm service
[Root @ localhost ~] # Chkconfig php-fpm on set startup
Preparation
1. Configure nginx to support PHP
[Root @ localhost ~] # Cp/etc/nginx. conf/etc/nginx. conf. bak
[Root @ localhost ~] # Vim/etc/nginx. conf
User nginx; # Modify the nginx running account to: nginx user in the nginx group!
[Root @ localhost ~] # Cp/etc/nginx/conf. d/default. conf/etc/nginx/conf. d/default. conf. bak
[Root @ localhost ~] # Vim/etc/nginx/conf. d/default. conf
Index. php index.html index.htm;
Location ~ \. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_param PHP_VALUE "open_basedir = $ document_root:/tmp/"; add this line to prevent cross-site
Include fastcgi_params;
}
# Cancel the location comment of the FastCGI server and change the parameter of the fastcgi_param line to $ document_root $ fastcgi_script_name or use the absolute path.
2. php configuration
[Root @ localhost ~] # Vim/etc/php. ini
Date. timezone = PRC
Expose_php = Off
#; Open_basedir =.:/tmp/comment out this line
3. Configure php-fpm
[Root @ localhost ~] # Vim/etc/php-fpm.d/www. conf Edit
User = nginx: The editing user is nginx.
Group = nginx change group to nginx
[Root @ localhost ~] #/Etc/init. d/mysqld restart mysql
[Root @ localhost ~] #/Etc/init. d/nginx restart start nginx
[Root @ localhost ~] #/Etc/rc. d/init. d/php-fpm restart Php-fpm
Test
[Root @ localhost ~] # Cd/usr/share/nginx/html/enter the default nginx website root directory
[Root @ localhost html] # cat index. php create an index. php file
<?
Phpinfo ()
?>
[Root @ localhost html] # chown nginx. nginx/usr/share/nginx/html/-R is set as the Directory owner
[Root @ localhost html] # chmod 700/usr/share/nginx/html/-R set directory permissions
Remarks
[Root @ localhost ~] # Cd/usr/share/nginx/html/nginx default program directory
[Root @ localhost ~] # Chown nginx. nginx/usr/share/nginx/html/-R permission settings
[Root @ localhost ~] # The cd/var/lib/mysql/Database Directory is
[Root @ localhost ~] # Chown mysql. mysql-R/var/lib/mysql/permission settings
[Root @ localhost html] # tail-n20/var/log/nginx/error. log to view nginx logs
Software version
[Root @ localhost html] # nginx-v
Nginx version: nginx/1.6.2
[Root @ localhost html] # php-v
PHP 5.4.36 (cli) (built: Dec 22 2014 16:06:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
[Root @ localhost html] # mysql-u root-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 2
Server version: 5.5.41-cll-lve MySQL Community Server (GPL) by Atomicorp
The installation and configuration of lnmp is relatively simple, mainly because it is difficult to configure security configurations and performance. This is only a step-by-step test based on your website needs.