Configure lnmp architecture

# make & make install

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

work process:

Client user request --> through cdn, 4lb load balancing, etc. --> server nginx --> if the user request is a static page such as html --> nginx returns the result directly.

Client user request --> through cdn, 4lb load balancing, etc. --> server nginx --> if the user request is a dynamic page --> the request is transferred to the fastcgi protocol --> then sent to the php-fpm process --> further Forward to the worker process wrapper --> then to the php service --> if you need to access the mysql database --> return the result to php --> php-fpm --> fastcgi --> nginx --> clint

Build lnmp architecture

Compile mysql (source package download address: https://downloads.mysql.com/archives/community/ )

# tar zxf mysql-boost-5.7.30.tar.gz  解压# cd mysql-5.7.30/# useradd -s /sbin/nologiin -M mysql安装前创建 mysql 用户来启用Mysql 服务 没有安装cmake提前安装# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \ #指定安装的位置> -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \	#指定套接字文件的位置> -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \	> -DEXTRA_CHARSETS=all \> -DDEFAULT_CHARSET=utf8 \> -DDEFAULT_COLLATION=utf8_general_ci \> -DWITH_MYISAM_STORAGE_ENGINE=1 \	#存储引擎> -DWITH_INNOBASE_STORAGE_ENGINE=1 \	#存储引擎> -DWITH_MEMORY_STORAGE_ENGINE=1 \	#存储引擎> -DWITH_READLINE=1 \	#支持readline库> -DENABLED_LOCAL_INFILE=1 \	#加载本地数据> -DMYSQL_USER=mysql \	#只定mysql用户为运行> -DMYSQL_TCP_PORT=3306	#指定运行端口> -DWITH_BOOST=boost/boost_1_59_0 #指定boost

During the installation process, there will be some errors and some components need to be installed. Follow the prompts to install ().devel. The components required for my installation process are gcc-c++, ncurses-devel, bison. After the installation is complete, delete the rm -fr CMakeCache.txt (this file is the pre-compiled cache). Compile and install after all components are resolved

# make & make install
# cd /usr/local/lnmp/mysql/# mkdir data    编译时指定的目录# chown -R mysql data/  修改目录的拥有者
# cp mysql-test/include/default_my.cnf /etc/my.cnf  复制配置文件# cp -a support-files/mysql.server /etc/init.d/mysqld# chmod +x /etc/init.d/mysqld 给脚本执行权限# chkconfig mysqld on  设置开机启动# ln -s /usr/local/lnmp/mysql/bin/* /usr/local/bin/   做软连接# mysqld --user=mysql --initialize   初始化(完成后生成一个密码)# systemctl start mysqld# systemctl status mysqld.service

At this time, you can use the generated password to log in to the database, but you cannot view the database without security initialization. So it needs to be safe initialization; safe initialization is directly here

# mysql_secure_installation 安全初始化修改完密码后便可以登录数据库查看# mysql -uroot -pBp4890731+mysql> show databases;

Compile php (source code package download address: https://www.php.net/downloads.php#gpg-7.4.5 )

# tar zxf php-7.4.20.tar.gz 解压# cd php-7.4.20/#  ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-s  预编译

The components that need to be installed during the compilation process are libpng-devel, libxml2-devel, and sqlite-devel. (Oniguruma, oniguruma-devel) These two installation packages need to be downloaded from the Internet, the download address (  http://down.24kplus.com/linux/oniguruma/oniguruma-devel-6.7.0-1.el7.x86_64.rpm , http://down.24kplus.com/linux/oniguruma/oniguruma-6.7.0-1.el7.x86_64.rpm ). After the compilation is complete, make install.

# rpm -ivh oniguruma-6.7.0-1.el7.x86_64.rpm oniguruma-devel-6.7.0-1.el7.x86_64.rpm  安装组件继续编译编译完成后# make insatll

Edit configuration file

# cd /usr/local/lnmp/php/# cp etc/php-fpm.conf.default etc/php-fpm.conf# vim etc/php-fpm.conf  此文件中需要打开php进程
# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf# vim etc/php-fpm.d/www.conf 更改配置中的user和group
最后复制源码中的主配置文件# cp /root/Downloads/php-7.4.20/php.ini-development etc/php.ini# vim etc/php.ini  更改时区
# cp /root/Downloads/php-7.4.20/sapi/fpm/init.d.php-fpm /etc/init.d/php.fpm 复制启动脚本# chmod +x /etc/init.d/php.fpm 加执行权限# useradd -s /sbin/nologin -M nginx 添加nginx用户# /etc/init.d/php.fpm start  开启服务# netstat -antlp 查看端口   

Compile nginx (download address of source package: http://nginx.org/en/download.html )

# tar zxf nginx-1.18.0.tar.gz  解压# cd nginx-1.18.0/# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx 编译# make install、# nginx/sbin/nginx -V

After the installation is complete, you can check the version number. We need to delete the variables after the version number and comment out debug

# vim /root/Downloads/nginx-1.18.0/src/core/nginx.h

Then delete the nginx directory and recompile

# make & make install# cd /usr/local/lnmp# vim conf/nginx.conf 添加index.php文件,首先访问此文件。之后需要开启php连接模块,发布页面时index.php,直接访问fastcgi.conf

Then turn on the service

# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin 做软连接# nginx -t 语法检查# nginx 开启服务  (nginx -s reload 重新加载)

Visit test:

Write a php page

# vim conf/nginx.conf

Test: lnmp architecture completed