LNMP architecture installation

1. Starting from version 1.20 of nginx, the official library is the same as the large version of epel, and the small version number of epel is updated. If you want to install the official, it is recommended to download the corresponding software package directly from the official

yum install -y http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.1-1.el7.ngx.x86_64.rpm

1) Installation

Upload mysql57.35.tar.gz and php72.tar.gz to web01 through xshell

tar xf mysql57.tar.gz
tar xf php72.tar.gz
yum localinstall -y nginx* mysql57/* php72/*

2) Edit profile

mv /etc/nginx/conf.d/default.conf{,.bak}
vim /etc/nginx/conf.d/www.conf
server {
	listen 80;
	server_name www.ly.com;
	root /web/www;
	index index.php index.html;
	
  	location ~ \.php$ {
      	fastcgi_pass   127.0.0.1:9000;
      	fastcgi_index  index.php;
      	#$document_root is the value of root, $fastcgi_script_name is the uri to access
      	fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      	#Parameters of fastcgi protocol
      	include        fastcgi_params;
    }
}

3) Create site directory and index pages

mkdir -p /web/www/
vim /web/www/index.php
<?php
    phpinfo();
?>

4) Start nginx and PHP FPM

systemctl start nginx php-fpm
systemctl enable nginx php-fpm

Check whether the port is listening
lsof -i:9000
lsof -i:80

5) Client browser access http://www.ly.com , if you can access the normal php information page, it means that the LNP deployment is complete (remember to modify the hosts file)

6) Deploy the kaoshi.zip page to achieve the effect of uploading
a. Upload kaoshi.zip through xshell
b. Release kaoshi.zip to the web site directory

unzip -d /web/www/upload kaoshi.zip 


c. Check www.conf of nginx to see if there is a statement supporting index.html

vim /etc/nginx/conf.d/www.conf
...
    index index.php index.html;
...


d. Restart nginx service and access http://www.tf.com/upload , upload the file. The page displays successfully, but it doesn't
e. Modify the directory ownership so that the program user of nginx can have write permission

chown -R nginx.nginx /web/www/upload


f. Upload again, the page is displayed successfully, but it is still not successful. Modify the program user of PHP FPM, which is consistent with nginx
 

The first method:
sed -i '/^user/c user = nginx' /etc/php-fpm.d/www.conf
sed -i '/^group/c group = nginx' /etc/php-fpm.d/www.conf

The second method:
sed -ri '/^(user|group)/s#(.*)= apache#\1= nginx#' /etc/php-fpm.d/www.conf

The third method:
sed -i 's#apache#nginx#' /etc/php-fpm.d/www.conf

g. Restart PHP FPM and upload again. Success

systemctl restart php-fpm

h. When uploading a large file, an error of 413 Request Entity Too Large is reported, indicating that the default LNP upload file size is limited

The configuration items for nginx+php to realize the upload file size limit are as follows:
1) The configuration items of nginx can be in http{},server{},location {}, and the default settings are 1m

client_max_body_size 200m;


2) Modify the php configuration file

vim /etc/php.ini
#The file upload function is enabled by default
file_uploads = On
#The maximum upload file size is 2M by default
upload_max_filesize = 200M
#Maximum file size, default 8M
post_max_size = 200M
#The maximum number of files that can be uploaded by a request  , Default 20
max_file_uploads = 20

At this point, LNP deployment is completed

7) Deploy mysql5.7
Installation strategy
a. Start mysql service

systemctl start mysqld

b. Change the password of administrator root
 

There are two ways:
First: log in to mysql After, use alter Statement modification
mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tf123.com';

Second: use mysqladmin Management tool modification
mysqladmin -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log) password 'Tf123.com'
#If root does not have a password
mysqladmin -uroot  password 'ly123.com'

mysql and mysqladmin Grammar of

mysql -u'username' -p'password' -h'hostname'
mysql -uroot -pTf123.com -h10.0.0.51

mysqladmin -u'username' -p'oldpassword' password 'newpassword'

c. Create a page to test php connection to mysql
 

vim /web/www/mysqli.php
<?php
        $servername = "localhost";
        $username = "root";
        $password = "ly123.com";

        // Create connection
        $conn = mysqli_connect($servername, $username, $password);

        // Detect connection
        if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
        echo "Connection succeeded";
?>

d. Visit http://www.ly.com/mysqli.php
You can see that the connection is successful and the LNMP deployment is completed

8) Deploy LNMP application wordpress
a. Download wordpress source package

wget https://cn.wordpress.org/wordpress-5.7-zh_CN.tar.gz
#Download the latest version
wget https://cn.wordpress.org/latest-zh_CN.tar.gz

b. Unzip and move to the web site directory to modify the attribution

tar xf wordpress-5.7-zh_CN.tar.gz
mv wordpress /web/blog
chown -R nginx.nginx /web/blog

c. Add site profile for blog

cp /etc/nginx/conf.d/{www,blog}.conf
sed -i 's#www#blog#' /etc/nginx/conf.d/blog.conf

d. Overloaded nginx

systemctl reload nginx

e. Log in to the database, create the required libraries for wordpress, and authorize

mysql -uroot -p'ly123.com'
> create database wordpress;
> grant all on wordpress.* to 'webadm'@'localhost' identified by 'ly123.com';

f. Browser access http://blog.tf.com , install the site as prompted

9) Deploy LNMP application wecenter (Zhihu)
a. Get WeCenter source package

b. Unzip and move to the web site directory to modify the attribution

unzip WeCenter_3-2-2.zip
mv WeCenter322/ /web/zh
chown -R nginx.nginx /web/zh

c. Add site profile for blog

cp /etc/nginx/conf.d/{www,zh}.conf
sed -i 's#www#zh#' /etc/nginx/conf.d/zh.conf

d. Overloaded nginx

systemctl reload nginx

e. Log in to the database, create the required libraries for wordpress, and authorize

mysql -uroot -p'ly123.com'
> create database zh;
> grant all on zh.* to 'webadm'@'localhost' identified by 'ly123.com';

f. Browser access http://zh.ly.com , install the site as prompted

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Troubleshooting ideas

1. Test grammar nginx -t
2.systemctl start|restart nginx -> systemctl status nginx -l
Current error: address already use   Port 80 occupied
ss -lntp | grep :80
Kill process name
3. The service is started successfully. There is an access error. See the log errorlog
4. Pass status code
502 
503 
5. The software package is installed successfully
yum history 
yum history undo ID
6. Check domain name resolution
ping domain name

Keywords: CentOS Nginx architecture

Added by yacahuma on Tue, 02 Nov 2021 16:42:27 +0200