Implement LNMP architecture, deploy WordPress and configure NGINX virtual host

Keywords: Linux PHP Nginx MariaDB MySQL

1. Compile and install LNMP and wordpress

1.1 install PHP, php mysql, mysql, PHP FPM

[root@c1 ~]# yum install  php php-mysql ngnix  mariadb-server php-fpm -y

1.2 compile and install nginx

1.2.1 installation dependency package

[root@c1 nginx]# yum install gcc pcre-devel openssl-devel zlib-devel -y

1.2.2 creating nginx users

[root@c1 ~]# useradd -r -s /sbin/nologin nginx

1.2.3 download the nginx source package on the official website, decompress it, compile and install it

[root@c1 src]# pwd
/usr/local/src
[root@c1 src]# ls
nginx-1.16.1.tar.gz
[root@c1 src]# tar xf nginx-1.16.1.tar.gz 
[root@c1 src]# ls
nginx-1.16.1  nginx-1.16.1.tar.gz
[root@c1 src]# mv nginx-1.16.1 nginx
[root@c1 src]# cd nginx/
[root@c1 nginx]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@c1 nginx]# ./configure --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio
[root@c1 nginx]# make -j 4 && make install

1.2.4 configure environment variables for convenient startup of nginx

[root@c1 sbin]# export PATH="/usr/local/nginx/sbin:$PATH"

1.2.5 modify the nginx configuration file so that fstcgi processes the page with the. php suffix

[root@c1 nginx]# vim /usr/local/nginx/conf/nginx.conf  ###Add the following line to the configuration file
include       /usr/local/nginx/conf.d/*.conf;
[root@c1 conf.d]# pwd
/usr/local/nginx/conf.d
[root@c1 conf.d]# cat wordpress.conf 
server {
        listen       80;
        server_name  www.zhuweijun.com;
        root /data/php;
        index index.php;
        location ~* \.php$ {
                root /data/php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

1.2.6 create corresponding directory and start NGINX and PHP FPM services

[root@c1 nginx]# mkdir /data/php
[root@c1 nginx]# systemctl start php-fpm   ###Start PHP FPM service
[root@c1 nginx]# nginx    ###Start nginx service

1.3 creating wpdb database and wpuser remote connection in database server

[root@c1 ~]# systemctl start mariadb
[root@c1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on wpdb.* to wpuser@'%' identified by "wppass";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
###Test remote connection database
[root@c1 nginx]# mysql_secure_installation ##Run down security hardening script
[root@c1 ~]# mysql -uwpuser -pwppass -hc1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

1.4 download and decompress wordpress blog program on the official website to the website directory and prepare WordPress configuration file

[root@c1 php]# pwd
/data/php
[root@c1 php]# ls
wordpress  wordpress-5.0.3-zh_CN.zip
[root@c1 php]# mv wordpress/* .
[root@c1 php]# ls
index.php                  wp-blog-header.php    wp-load.php
license.txt                wp-comments-post.php  wp-login.php
readme.html                wp-config-sample.php  wp-mail.php
wordpress                  wp-content            wp-settings.php
wordpress-5.0.3-zh_CN.zip  wp-cron.php           wp-signup.php
wp-activate.php            wp-includes           wp-trackback.php
wp-admin                   wp-links-opml.php     xmlrpc.php
[root@c1 php]# cp -r * /data/nginx/
###Prepare wordpress profile
[root@c1 php]# cp wp-config-sample.php wp-config.php
[root@c1 php]# vim wp-config.php
define('DB_NAME', 'wpdb');

/** MySQL Database user name */
define('DB_USER', 'wpuser');

/** MySQL Database password */
define('DB_PASSWORD', 'wppass');

1.5 setting wordpress directory permissions

[root@c1 html]#  setfacl -R -m u:nginx:rwx /data

1.6 modify the host file of Windows system

C:\Windows\System32\drivers\etc\hosts
 Edit the hosts file and add the following line:
10.0.1.242 www.zhuweijun.com admin.zhuweijun.com

1.7 open in browser http://www.zhuweijun.com Perform page installation




2. Configure virtual hosts, www.x.com The domain name realizes the home page access, and the admin.x.com domain name realizes the background access of wordpress.
2.1 modify the configuration file of nginx based on Section 1

[root@c1 conf.d]# pwd
/usr/local/nginx/conf.d
[root@c1 conf.d]# cat wordpress.conf 
server {
        listen       80;
        server_name  www.zhuweijun.com;
        root /data/php;
        index index.php;
        location ~* \.php$ {
                root /data/php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

server {
        listen       80;
        server_name  admin.zhuweijun.com;
        root /data/php;
        index wp-login.php;
        location ~* \.php$ {
                root /data/php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

2.2 testing

#Reload nginx configuration
[root@c1 conf.d]# nginx -s reload


Posted by murali on Mon, 01 Jun 2020 07:59:42 -0700