Simple version of lnmp architecture construction (Linux+Nginx+Mysql+PHP)

 LNMP represents: the website server architecture of "Nginx+Mysql+PHP" under the Linux system.

Nginx is a high-performance HTTP and reverse proxy server,

MYSQL is a small relational database management system that can be replaced by mariadb.

PHP is a scripting language for embedded HTML text executed on the server side to connect to the database and provide dynamic files (the html files provided by nginx are static files), which is equivalent to an extension on the basis of the original html.

These four types of software are all free and open source software. When combined together, they become a free, efficient, and highly scalable website service system.

Functions required by linux system:

1. Smooth network

2. The yum source warehouse can provide corresponding

3. The configuration of selinux and firewall can be completely closed in the experimental environment. If it is necessary to open the firewall port and configure selinux in the real scene, it will be mentioned in the following download

This environment is an experimental environment

Necessary steps for nginx:

1. Download nginx (yum installation, source code installation) This experiment is all yum installation (the source code is too long, too lazy to write)

yum -y install nginx

2. You can access it without changing any files. Just access the local loopback address 127.0.0.1 on this machine.

3. Check the access port ss -anput | grep 80 and it will show that it is monitoring, which proves that there is no problem.

Extension: Open the firewall and selinux, open the tcp port 80 of the firewall and allow the http protocol.

PHP necessary steps:

1. Download php 

yum -y install php (it is best to choose local yum for this installation, so as not to change the version too high, centos8 does not have local yum, you can choose Alibaba cloud mirror station to download yum mirror source)

2. PHP configuration file changes (apache occupied the market before nginx came out, so some configurations in the php configuration file are still changed according to apache configuration)

vim /etc/php-fpm.conf (nginx process configuration file, no need to change here)

vim /etc/php-fpm.d/www.conf (the extended configuration file of nginx needs to be changed, and it will take effect in the main configuration file after the change. If you don’t understand it, you can open it. For the nginx process configuration file, see the last line)

The following is the location that needs to be changed (extension: vim enters the file shift+: set nu to display the line number)

     4 [www]

    24 user = nginx

    26 group = nginx

    38 listen = 10.0.0.17:9000 (add a new line, this address is a local address)

    55 listen.acl_users = apache,nginx

    64 listen.allowed_clients = 10.0.0.15 #Client address range allowed to connect

   104 pm = dynamic php uses php-fpm. The number of processes is dynamic.

   115 pm.max_children = 50 Number of php-fpm processes started in static state 

   120 pm.start_servers = 15 Number of php-fpm processes started in dynamic state

   125 pm.min_spare_servers = 5   Minimum number of php-fpm processes in dynamic state

   130 pm.max_spare_servers = 35 Maximum number of php-fpm processes in dynamic state

   261 access.log = /var/log/php-fpm/$pool.access.log

3. PHP cannot be accessed at this time. You need to change the configuration file of nginx so that it can accept PHP dynamic file output.

vim /etc/nginx/nginx.conf

Set the website homepage as shown below

 The picture below is to change the nginx configuration file to add the php dynamic file forwarding function (in vernacular)

 Set php accessible files

vim /usr/share/nginx/html/index.php (php homepage)

<?php
phpinfo();
?>
After setting up, you can access the local IP address

Description of necessary steps for mysql:

First log in to MySQL

1.mysql -u root -p

mysql> use mysql;

mysql> update user set password=password('123') where user='root' and host='localhost';

mysql> flush privileges;

2. First log in to MySQL.

Format: mysql> set password for username@localhost = password('new password');

Add new user permissions

Grant all  privileges on *.* to ‘lxz’@172.24.3.50 identified by ‘redhat’;

[root@nginx ~]# cat /usr/local/nginx/html/con_db.php

<?php

$link=mysqli_connect('172.24.3.50','lxz','redhat');

if($link)

echo "success";

else

echo "fail";

mysqli_close($link);

?>

Extension: There is a problem when accessing 127.0.con_db.php in the experimental state. Open the firewall 3306/tcp port and enable the selinux boolean value.

The following figure is used to view the log files that the Boolean value has not opened after the firewall is turned on.

View the required boolean value

 setsebool -P httpd_can_network_connect_db 1 After turning on the Boolean value, you can access

 

Guess you like

Origin blog.csdn.net/m0_73165149/article/details/127337782