LNMP Architecture Overview and build (compile source code Nginx, MYSQL, PHP)

LNMP Architecture Overview and build (compile source code Nginx, MYSQL, PHP)

1. What is LNMP

LNMP refers to a set of commonly used together to run dynamic Web sites or servers acronym for the name of free software. L refers to Linux, N refers Nginx, M generally refers MySQL, may refer MariaDB, P generally refers to PHP, Perl, or may also refer to Python.

In general, the representative of the LNMP is: Linux system Nginx + MySQL + PHP this web server architecture.

LNMP = Linux+Nginx+Mysql+PHP

  • Linux is a Unix-like computer operating system collectively, is the most popular free operating system. Representatives versions: debian, centos, ubuntu, fedora, gentoo and so on.
  • Nginx is a high-performance HTTP and reverse proxy server is a IMAP / POP3 / SMTP proxy server.
  • Mysql is a small relational database management systems.
  • PHP is an HTML document embedded scripting language which is performed on the server side.
  • These four software are free and open source software, combined together into a free, efficient, extensible web service system.

Nginx is in PHP fastcgi way to combine the Nginx can be understood as the agent of the PHP fastcgi Nginx.

The only difference is LNMP and LAMP refers to the provision of web services is Nginx instead of Apache: In Apache, PHP as a module exists. In the Nginx, PHP is present as an independent service, this service is called php-fpm;. Nginx handling the static direct request, the request will be forwarded to the dynamic php-fpm.

2. LNMP works

  • Http request the browser sends a request to a server (Nginx)
  • Server response and processing web requests, will save some static resources (CSS, images, video, etc.) on the server, then the php script interface transfer protocol (IGP) PHP-FCGI (fast-cgi) transmitted to PHP-FPM (process manager)
  • PHP-FPM not treated, then PHP-FPM calls the process PHP parser, PHP parser php script information.
  • PHP parser process can launch multiple, concurrent execution. Then the script parsed return to PHP-FPM
  • PHP-FPM another script information in the form of fast-cgi will be sent to Nginx
  • Server and then sent to the browser in the form of Http response.
  • The browser then parses and rendering and rendering.

3. MYSQL database source compiler

step1-extracting installation mysql:

tar zxf mysql-boost-5.7.28.tar.gz

step2 create mysql user:

useradd -s /sbin/nologin -M mysql

step3 compiler MYSQL:
cmake cross-platform tools are used to pre-compile the source code mysql, mysql is used to set compiler parameters. Such as: the installation directory, data storage directory, character encoding, collation, etc.

yum install -y cmake	#编译mysql需要用的包
cd mysql-5.7.28	#进入mysql解压后的目录
#以下命令为编译:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \			#安装位置
> -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \ 	#指定套接字文件位置
> -DEXTRA_CHARSETS=all \ 										#扩展字符集
> -DDEFAULT_CHARSET=utf8 \										#默认字符集
> -DDEFAULT_COLLATION=utf8_general_ci \							#默认字符校对
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \							#安装myisam 存储引擎
> -DWITH_MYISAM_STORAGE_ENGINE=1 \								#安装innodb存储引擎
> -DWITH_MEMORY_STORAGE_ENGINE=1 \								#安装memory存储引擎
> -DWITH_READLINE=1 \											#支持readline库
> -DENABLED_LOCAL_INFILE=1 \									#启用加载本地数据
> -DMYSQL_USER=mysql \											#指定mysql运行用户
> -DMYSQL_TCP_PORT=3306											#指定mysql端口

step4 Follow the prompts to resolve dependencies:

yum install -y gcc gcc-c++ ncurses-devel openssl-devel -y

step5 may see this error:

CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
This CMake script will look for boost in <directory>. If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80

solve:

缺少 -DWITH_BOOST=<directory>参数
重新编译时加上下面的参数: 
-DWITH_BOOST=boost/boost_1_59_0/

Recompile, you need to remove the original object files and cache information:

make clean
rm -fr CmakeCache.txt

Behind the compilation process may be a warnin:

CMake Warning at cmake/bison.cmake:20 (MESSAGE):
Bison executable not found in PATH
Call Stack (most recent call first):
sql/CMakeLists.txt:514 (INCLUDE)

solve:

yum install -y bison

step6 installation:

make && make install ##如果 make 还有问题,删除原来的目录,重新解压编译(安装过程较长) 

step7 modify permissions:

cd /usr/local/lnmp/mysql
mkdir data
chown -R root .
chown -R mysql data
ln -s /usr/local/lnmp/mysql/bin/* /usr/local/bin/

step8 copy the configuration file:

cd /usr/local/lnmp/mysql/mysql-test/include
cp default_my.cnf /etc/my.cnf
cd /usr/local/lnmp/mysql/support-files
cp -a mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
systemctl status mysqld

step9 initialization:

mysqld --user=mysql --initialize	#以mysql 用户身份初始化
注意:初始化会生成一个临时密码,用于登录 mysql(要记住此密码)
比如:2019-01-03T09:06:09.448851Z 1 [Note] A temporary password is generated
for root@localhost: r#9VqAoA/au
r#9VqAoA/au就是临时密码

step10 start mysql:

systemctl start mysqld

step11 enter mysql:

mysql -uroot -pr#9VqAoA/au: #使用刚才的临时密码(会有报错,所以需要安全初始化)

step12 safe for initialization:

mysql_secure_installation	#然后会提示是否启用密码检测插件,直接回车不启用,否则会要求密码有大小写和特殊字符等要求;剩余全部选 y

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

mysql installation configuration

4. PHP source compiler

step1 extracting installation package:

tar zxf php-7.4.1.tar.gz

step2 resolve dependencies:

yum -y install bzip2

step3 into the unpacked directory, start the compilation:

./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-sockets \
--with-pdo-mysql=/usr/local/lnmp/mysql \
--enable-gd \
--without-pear \
--enable-fpm

step4 according to the compilation process of being given the gradual resolution of dependencies:
You may need to install the package:

yum install -y libxml2-devel
yum install -y libpng-devel
yum install -y oniguruma-*

step5 installation:

make && make install

step6 copy change the configuration file:

cd /usr/local/lnmp/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf		#开启17行:pid = run/php-fpm.pid

Here Insert Picture Description
step7 copy sub configuration file:

cd /usr/local/lnmp/php/etc/php-fpm.d
cp www.conf.default www.conf
vim www.conf	#更改23和24行内容如下
user = nginx
group = nginx

Here Insert Picture Description

Here Insert Picture Description

step8 master copy change php configuration file:

cd php-7.4.1
cp php.ini-production /usr/local/lnmp/php/etc/php.ini
vim /usr/local/lnmp/php/etc/php.ini	#961行修改时区如下
date.timezone = Asia/Shanghai

Here Insert Picture Description

step9 copy php startup script to /etc/init.d/:

cd /root/lnmp/php-7.4.1/sapi/fpm
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm	#添加执行权限

step10 start php:

/etc/init.d/php-fpm start

Note:
Start nginx user error possible because there is no need to manually create

useradd -u 900 nginx

Here Insert Picture Description
php installation configuration

5. nginx source compiled

step1 extracting installation package

tar zxf nginx-1.16.0.tar.gz

step2 remove the version number of nginx:

cd /root/lnmp/nginx-1.16.0
vim src/core/nginx.h	

Here Insert Picture Description

step3 to close debug:

Because the debug log is very large, companies generally do not need to open

vim auto/cc/gcc
做如下修改:
# debug
#CFLAGS="$CFLAGS -g" (将这2行注释调,关闭debug)

Here Insert Picture Description

step4 compile and install nginx:

./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx

step5 resolve dependencies follow the prompts:
Here you should also need to install pcre-devel:

yum install pcre-devel -y

step6 installation:

make && make install

step7 modify nginx configuration files, enable php modules:

cd /usr/local/lnmp/nginx/conf
vim nginx.conf

Here Insert Picture Description
step8 the nginx startup script link to / usr / local / sbin /:

ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/

step9 open nginx:

nginx -t ##检测语法
nginx

Here Insert Picture Description

step10 test:

尝试访问http://172.25.254.1	##是nginx默认页面

Here Insert Picture Description
Nginx release directory is added by default index.php:

vim /usr/local/lnmp/nginx/html/index.php
写入:
<?php
phpinfo()
?>

Here Insert Picture Description
Refresh http://172.25.254.1 can see the default page of php
Here Insert Picture Description

nginx installation configuration

Published 175 original articles · won praise 11 · views 6037

Guess you like

Origin blog.csdn.net/weixin_45775963/article/details/104592027