Web server cluster - LNMP dynamic website deployment

Posted by mabus on Mon, 31 Jan 2022 19:07:51 +0100

1, Foreword

1.1 LNMP overview

LNMP refers to a group of free software acronyms commonly used together to run dynamic websites or servers. L refers to Linux, N refers to Nginx, M generally refers to MySQL, MariaDB, P generally refers to PHP, Perl or Python.

1.2 LNMP introduction

  • LNMP represents the website server architecture of Nginx+MySQL+PHP under Linux system.
  • Linux is a general term of Unix computer operating system. It is the most popular free operating system at present. Representative versions include debian, centos, ubuntu, fedora, gentoo, etc.
  • Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.
  • Mysql is a small relational database management system.
  • PHP is a scripting language embedded in HTML documents executed on the server side.
  • These four kinds of software are free and open source software, which are combined to become a free, efficient and scalable website service system.

1.3 Nginx features

  • Nginx is a small and efficient Web server software under Linux. It is Rambler with the second largest number of visits in Russia by Igor Sysoev
    The site has been developed and has been running on some large websites in Russia for many years, which is quite stable.
  • Nginx has stable performance, rich functions, simple operation and maintenance, fast processing speed of static files and little consumption of system resources

1.4 Nginx benefits

  • As a Web server: compared with Apache, Nginx uses less resources and supports more concurrent connections, reflecting higher efficiency.
  • As a load balancing server: nginx can support both Rails and PHP internally and serve externally as an HTTP proxy server. Nginx
    Written in C, both system resource overhead and CPU efficiency are much better than Perlbal.
  • As a mail proxy server: Nginx is also an excellent mail proxy server (one of the earliest purposes of developing this product is also as a mail proxy server). Last/fm describes the successful and wonderful experience.
  • Nginx installation is very simple, and the configuration file is very concise (it can also support perl syntax). Nginx supports smooth loading of new configurations and software version upgrading without interruption of service.

2, Detailed deployment process

2.1 Nginx deployment

Nginx version is based on nginx 1.16.1

[root@lnmp ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@lnmp ~]# yum -y install nginx
[root@lnmp ~]# systemctl start nginx
http://192.168.100.10 / # browser input IP to check whether the installation of Nginx is completed

2.2 PHP FPM deployment

[root@lnmp ~]# yum -y install php-fpm php-mysql php-gd
#php FPM: php program that accepts dynamic requests
#php mysql: a program that connects php to mysql
#PHP Gd: graphics library program (GD library can process pictures or generate pictures)
[root@lnmp ~]# systemctl restart php-fpm
[root@lnmp ~]# systemctl enable php-fpm
[root@lnmp ~]# netstat -anpt | grep 9000

After installing php.1.2

[root@lnmp ~]# vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>                                                 #Version information of calling function php

Note: version 1.16.1 server is located in the main configuration file

[root@lnmp ~]# vim /etc/nginx/nginx.conf
location / {
        index index.php index.html;
        }                                          #Add php and html home page priority access order in location

#Start nginx_fastcgi function
#Add the following configuration to the server
        location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        }
[root@lnmp ~]# systemctl restart nginx

2.2.1 verification after PHP configuration

http://192.168.100.10 / # browser access

2.3 MySQL deployment

[root@lnmp ~]# yum -y install mariadb-server mariadb   #Install MySQL server program and client program
[root@lnmp ~]# systemctl start mariadb
[root@lnmp ~]# systemctl enable  mariadb
[root@lnmp ~]# mysqladmin password '123456'           #Change the database password to 123456
[root@lnmp ~]# mysql -uroot -p123456                  #Login database
MariaDB [(none)]> create database bbs;                #Prepare database
MariaDB [(none)]> grant all on bbs.* to phptest@'192.168.100.10' identified by '123456'; #Authorized test account
MariaDB [(none)]> flush privileges;                   #Refresh database

2.3.1 test the connectivity between php and MySQL

In the actual production environment, no matter how you deploy, you must remember to detect, whether it is separate deployment or integrated deployment

Currently, it is a converged deployment

[root@lnmp ~]# vim /usr/share/nginx/html/index.php        #Modify test page
<?php
$link=mysql_connect('192.168.100.10','phptest','123456'); #mysql_connect: connection between php language and database (): pass parameters
if($link)
        echo "Successfuly";
else
        echo "Faile";
mysql_close();
?>

2.4 business launch - WordPress

[root@lnmp ~]# wget https://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip
[root@lnmp ~]# unzip wordpress-4.9.1-zh_CN.zip
[root@lnmp ~]# rm -rf /usr/share/nginx/html/index.php                   #Delete test interface
[root@lnmp ~]# cp -rf /root/wordpress/* /usr/share/nginx/html         
[root@lnmp ~]# chown -R nginx.nginx /usr/share/nginx/html/*  
[root@lnmp ~]# chmod 777 /usr/share/nginx/html/                         #Of course, you can not give the right
http://192.168.100.10/

2.4.1 website login configuration

2.4.2 website background configuration

2.4.3 login after configuration

3, To sum up

  • The Nginx configuration files are basically the same, but the version problem exists in different locations. We need to draw inferences from one instance
  • As for the authorized account of the database, 192.168.100% was used at the beginning, php reported an error during the test. It was modified to the specific IP address and found that the test was successful

Topics: Linux CentOS