Web service source code compile and install LNMP

Related installation package
link: https://pan.baidu.com/s/1LysiQyLqHlmzZ5zWiCYDYQ
extraction code: 8wio

1. LNMP related concepts

  • LNMP is: the website server architecture of Nginx+MySQL+PHP under Linux system.
  • Compared with LAMP, the difference is the web server program-Nginx (LNMP) and Apache (LAMP)
    • Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.
Comparison item Nginx Apache
Configuration file concise complex
Use of resources Nginx saves resources more than Apache Take up more resources
Suitable for website status Static Dynamic interaction

Generally speaking, for web services that require performance, use nginx.
If you don’t need performance and just want stability, consider apache

Two, install Nginx service

premise

#关防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

Insert picture description here

1. Install dependencies

#nginx的配置及运行需要pcre、zlib等软件包的支持,因此需要安装这些安装的开发包,以便提供相应的库和头文件。
yum -y install pcre-devel zlib-devel gcc gcc-c++ make

Insert picture description here

2. Create a running user

  • The Nginx service program runs as nobody by default. It is recommended to create a special user account for it to control its access permissions more accurately
useradd -M -s /sbin/nologin nginx

Insert picture description here

3. Compile and install

cd /opt/
tar zxvf nginx-1.12.0.tar.gz

cd nginx-1.12.0/
./configure \
 --prefix=/usr/local/nginx \
 --user=nginx \
 --group=nginx \
 --with-http_stub_status_module

#-----配置命令解释
--prefix=/usr/local/nginx      #指定nginx的安装路径
--user=nginx                   #指定用户名
--group=nginx                  #指定组名
--with-http_stub_status_module #启用 http_stub_status_module 模块以支持状态统计
#-----

make && make install

Insert picture description here

4. Path optimization

#将应用程序nginx中可执行的命令做个软链接到环境路径变量中,让系统识别nginx的操作命令
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

Insert picture description here

5. Add Nginx system service

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

chmod 754 /lib/systemd//system/nginx.service
systemctl start nginx.service 
systemctl enable nginx.service

Insert picture description here

Three, install MySQL service

1. Install the Mysql environment dependency package

yum -y install  \
ncurses \
ncurses-devel \
bison \
cmake
#--------环境包解释------------
ncurses				#字符终端下图形互动功能的动态库
ncurses-devel 		#ncurses开发包
bison 				#语法分析器
cmake				#mysql需要用cmake编译安装

Insert picture description here

2. Create a running user

useradd -M -s /sbin/nologin  mysql

Insert picture description here

3. Compile and install

cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz

cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

make && make install

注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql     	#指定mysql的安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock   #指定mysql进程监听套接字文件(数据库连接文件)的存储路径
-DSYSCONFDIR=/etc                               #指定配置文件的存储路径
-DSYSTEMD_PID_DIR=/usr/local/mysql              #指定进程文件的存储路径
-DDEFAULT_CHARSET=utf8                          #指定默认使用的字符集编码,如 utf8
-DDEFAULT_COLLATION=utf8_general_ci  			#指定默认使用的字符集校对规则
-DWITH_EXTRA_CHARSETS=all 						#指定支持其他字符集编码
-DWITH_INNOBASE_STORAGE_ENGINE=1               #安装INNOBASE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1                #安装ARCHIVE存储引擎 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1              #安装BLACKHOLE存储引擎 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1            #安装FEDERATED存储引擎 
-DMYSQL_DATADIR=/usr/local/mysql/data         #指定数据库文件的存储路径
-DWITH_BOOST=boost           #指定boost的路径,若使用mysql和boost集成包安装则-DWITH_BOOST=/usr/local/boost
-DWITH_SYSTEMD=1								#生成便于systemctl管理的文件

存储引擎选项:
#MYISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。
#静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1
#可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema)
#常用的两个存储引擎是:MYISAM和INNOBASE(InnoDB).

Insert picture description here
Insert picture description here

4. Modify the mysql configuration file

#删除原配置项,再重新添加下面内容
vim /etc/my.cnf
#客户端设置
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

#服务全局设置
[mysqld]
#设置管理用户
user = mysql
#指定数据库的安装目录
basedir=/usr/local/mysql
#指定数据库文件的存储路径
datadir=/usr/local/mysql/data
#指定端口
port = 3306
#设置服务器字符集编码格式为utf8
character-set-server=utf8
#指定pid 进程文件路径
pid-file = /usr/local/mysql/mysqld.pid
#指定数据库连接文件
socket=/usr/local/mysql/mysql.sock
#设置监听地址,0.0.0.0代表允许所有,如允许多个IP需空格隔开
bind-address = 0.0.0.0
#禁用DNS解析
skip-name-resolve
#设置mysql的最大连接数
max_connections=2048
#指定默认存储引擎
default-storage-engine=INNODB
#设置数据库接收的数据包大小的最大值
max_allowed_packet=16M
#指定服务ID号
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

----------------------------------------------------------------------------------------------------------
sql_mode常用值如下:
NO_ENGINE_SUBSTITUTION
如果需要的存储引擎被禁用或未编译,那么抛出错误。不设置此值时,用默认的存储引擎替代,并抛出一个异常

STRICT_TRANS_TABLES
在该模式下,如果一个值不能插入到一个事务表中,则中断当前的操作,对非事务表不做限制

NO_AUTO_CREATE_USER
禁止GRANT创建密码为空的用户

NO_AUTO_VALUE_ON_ZERO
mysql中的自增长列可以从0开始。默认情况下自增长列是从1开始的,如果你插入值为0的数据会报错

NO_ZERO_IN_DATE
不允许日期和月份为零

NO_ZERO_DATE
mysql数据库不允许插入零日期,插入零日期会抛出错误而不是警告

ERROR_FOR_DIVISION_BY_ZERO
在INSERT或UPDATE过程中,如果数据被零除,则产生错误而非警告。默认情况下数据被零除时MySQL返回NULL

PIPES_AS_CONCAT
将"||"视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样的,也和字符串的拼接函数Concat相类似

ANSI_QUOTES
启用ANSI_QUOTES后,不能用双引号来引用字符串,因为它被解释为识别符

Insert picture description here

5. Change the owner group of the mysql installation directory and configuration file

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

Insert picture description here

6. Set the path environment variable

echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile
source /etc/profile

Insert picture description here

7. Initialize the database

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

Insert picture description here

8. Add mysqld system service

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
netstat -anpt | grep 3306

Insert picture description here

9. Modify the mysql login password

mysqladmin -u root -p password "123456"

Insert picture description here

Fourth, install and configure the PHP parsing environment

1. Installation environment dependent packages

yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

Insert picture description here

2. Compile and install

cd /opt
tar jxvf php-7.1.10.tar.bz2
cd /opt/php-7.1.10/

./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

make && make install

相关解释:
--prefix=/usr/local/php 				#指定将 PHP 程序的安装路径
--with-mysql-sock=/usr/local/mysql/mysql.sock  #指定mysql 数据库连接文件的存储路径
--with-mysqli   #添加 MySQL 扩展支持 #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定
--with-zlib     #支持zlib功能,提供数据压缩
--with-curl     #开启curl扩展功能,实现HTTP的Get下载和Post请求的方法
--with-gd       #激活gd 库的支持
--with-jpeg-dir #激活jpeg 的支持
--with-png-dir  #激活png 的支持
--with-freetype-dir
--with-openssl
--enable-fpm
--enable-mbstring  #启用多字节字符串功能,以便支持中文等代码
--enable-xml       #开启扩展性标记语言模块
--enable-session   #会话
--enable-ftp       #文本传输协议
--enable-pdo       #函数库
--enable-tokenizer #令牌解释器
--enable-zip       #ZIP压缩格式

Insert picture description here
Insert picture description here

3. Path optimization

ln -s /usr/local/php/bin/* /usr/local/bin/

Insert picture description here

4. Adjust the PHP configuration file

  • php has three configuration files
    • Main configuration file------php.ini
    • Process service configuration file------php-fpm.conf
    • Extended configuration file------www.conf

(1) Adjust the main configuration file

cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
#939行;取消注释,修改
date.timezone = Asia/Shanghai
#1170行;修改
mysqli.default_socket = /usr/local/mysql/mysql.sock

php -m

Insert picture description here
Insert picture description here

(2) Adjust the process service configuration file

cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
#17行;去掉注释符“;”
pid = run/php-fpm.pid

Insert picture description here

(3) Adjust the extended configuration file

cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf

Insert picture description here

5. Start php-fpm

#PHP-FPM(FastCGI Process Manager:FastCGI进程管理器),是一个PHPFastCGI管理器,由于Nginx服务器不能处理动态页面,需要把Nginx把动态请求交给php-fpm进程继续解析。
/usr/local/php/sbin/php-fpm  -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000

Insert picture description here

6. Configure Nginx to support PHP parsing

vim /usr/local/nginx/conf/nginx.conf
        #65行;取消注释并修改
        location ~ \.php$ {
    
    
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #将/scripts修改成nginx的工作目录
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
        
systemctl restart nginx.service

Insert picture description here

7. Test access page

vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

#使用浏览器访问
http://192.168.163.10/index.php

Insert picture description here
Insert picture description here

8. Verify the database

mysql -u root -p
#创建一个数据库
CREATE DATABASE bbs;
#把bbs数据库里面所有表的权限授予给bbsuser,并设置密码123456
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY '123456';
#刷新数据库
flush privileges;
#查看有哪些数据库
show databases;

vim /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.163.10','bbsuser','123456');
if($link) 
echo "<h1>Success!!</h1>";
else
echo "Fail!";
?>

Insert picture description here

Insert picture description here

5. Deploy the Discz community forum web application

1. Unzip the forum compressed package

cd /opt
unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
#上传站点更新包
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs

Insert picture description here

2. Change the owner of the forum directory

cd /usr/local/nginx/html/bbs
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/

chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/

Insert picture description here
Insert picture description here

3. Browser access verification

论坛页面访问
http://192.168.163.10/bbs/install/index.php

#填写数据库信息
数据库服务器:localhost     ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:123456
管理员账号:admin
管理员密码:admin123
#结束

#论坛内部页面
http://192.168.163.10/bbs/index.php
#论坛后台管理员页面
http://192.168.163.10/bbs/admin.php

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51326240/article/details/112510262