1. Demonstration environment:
IP |
installed package |
Version |
192.168.1.221 |
nginx epel )_ |
1.12.2 |
php |
5.4.16 |
|
php-fpm ( FastCGI Process Manager) |
||
php-mysql ( The driver required for PHP to connect to MySQL ) |
||
192.168.1.222 |
mariadb-server |
5.5.56 |
Note: CentOS 7.4 no longer has built-in mysql-server package
2. Build LNMP :
1. Preparation before installation:
(1) Proofreading server time
(2) Configure the epel source
2、安装nginx:# yum -y install nginx # systemctl start nginx.service # ss -tunlp | grep :80
Configuration files and directories:
Ø Main configuration file: /etc/nginx/nginx.conf
Ø Auxiliary configuration file: /etc/nginx/*
ØWeb page storage root directory: /usr/share/nginx/html
3. Install php : # yum -y install php , configuration file: /etc/php.ini
4. Install and configure php-fpm :
# yum -y install php-fpm
# vim /etc/php-fpm.d/www.conf , modify the values of the following parameters:
listen = 192.168.1.221:9000 // The address port that php-fpm listens to
listen.allowed_clients = 192.168.1.221 // The FastCGI client address that is allowed to connect
user = nginx
group = nginx
# systemctl start php-fpm.service
# ss -tunlp | grip: 9000
Configuration file:
Ø Main configuration file: /etc/php-fpm.conf
Ø Auxiliary configuration file: /etc/php-fpm.d/www.conf
5. Install and configure mariadb :
# yum -y install mariadb-server mariadb mariadb-devel
# systemctl start mariadb.service
# ss -tunlp | grip: 3306
mariadb configuration file: /etc/my.cnf
// Modify the root user password of the mariadb database to 123456 (default is empty), delete anonymous users, delete the test database, and reload the authorization table
# mysql_secure_installation
# mysql -uroot -p
MariaDB [(none)]> grant all on *.* to 'root'@'192.168.%.%' identified by '123456'; // Authorize root user to log in remotely
MariaDB [(none)]> flush privileges;
6. Install php-mysql : # yum -y install php-mysql
7. Configure nginx to support php :
# cd /etc/nginx
# cp nginx.conf nginx.conf.bak
# vim nginx.conf
# systemctl reload nginx.service
# systemctl restart php-fpm.service
3. Test LNMP :
# cd /usr/share/nginx/html
# vim index.php
Enter http://192.168.1.221/index.php in the browser :
Stop mariadb on 192.168.1.222 : # systemctl stop mariadb.service
The communication between mariadb and php is normal
Visit http://192.168.1.221
Fourth, install and configure WordPress :
WordPress is an open source, free Blog engine developed using PHP language and MariaDB database. Users can build their own Blog on servers that support PHP and MariaDB database . WordPress is a very powerful blogging system with numerous plugins, easy to extend, and very convenient to install and use. At present , WordPress has become the mainstream blog building platform. The download address is https://cn.wordpress.org/ , here wordpress-4.8.1-zh_CN.zip is used as an example.
# yum -y install unzip
# unzip -q wordpress-4.8.1-zh_CN.zip
# cp -a wordpress/ /usr/share/nginx/html
# cd /usr/share/nginx/html/wordpress
# cp wp-config-sample.php wp-config.php
# vim wp-config.php , modify the database related information:
# mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'%' identified by "123456";
MariaDB [(none)]> flush privileges;
# mysql -uwpuser -p
MariaDB [(none)]> show databases;
Modify the nginx configuration file and add index.php after the index parameter :
# vim /etc/nginx/nginx.conf
location / {
index index.php index.html index.htm;
}
# systemctl reload nginx.service
Enter http://192.168.1.221/wordpress in the browser :
Click on "Install WordPress ":
Click to Login":
Enter your username and password and click "Login":
Delete the installation file: # rm -rf /usr/share/nginx/html/wordpress/wp-admin/install.php
Blog front desk login address http://192.168.1.221/wordpress/
Blog background management address http://192.168.1.221/wordpress/wp-admin/
Fifth, install the XCache module:
Configure epel source, install XCache : # yum -y install php-xcache --> 3.1.1
# rpm -ql php-xcache --> /etc/php.d/xcache.ini、/usr/lib64/php/modules/xcache.so
# systemctl reload nginx.service
# systemctl restart php-fpm.service
XCache related modules loaded :