LNMP架构搭建Discuz论坛(实战!)
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,什么是LNMP架构LNMP平台就是Linux、Ngnix、 MySQL、 PHP的组合架构,需要Linux服务器、MySQL数据库、PHP解析环境MySQL安装配置为了与Nginx、PHP环境保持一致
千家信息网最后更新 2025年12月02日LNMP架构搭建Discuz论坛(实战!)
什么是LNMP架构
LNMP平台就是Linux、Ngnix、 MySQL、 PHP的组合架构,需要Linux服务器、MySQL数据库、PHP解析环境
MySQL安装配置
为了与Nginx、PHP环境保持一致,此处选择采用源代码编译的方式安装MySQL组件
MySQL部署的方法
- 编译安装MySQL
- 优化调整
- 初始化数据库
- 启动mysq|服务并设置root数据库账号的密码
PHP解析环境的安装
配置网页动静分离,解析PHP,有两种方法可以选择
- 使用PHP的FPM模块
- 将访问PHP页面的Web请求转交给Apache服务器去处理
较新版本的PHP已经自带FPM模块,用来对PHP解析实例进行管理、优化解析效率
- FastCGI将Http Server和动态脚本语言分离开
- Nginx专门处理静态请求,转发动态请求
- PHP_FPM专门 ]解析PHP动态请求
单服务器的LNMP架构通常使用FPM的方式来解析PHP,本次也使用FPM模块处理动态请求。
PHP编译安装步骤
- 编译安装PHP
- 编译选项时添加"--enable-fpm" 以启用此模块
- 安装后的调整,主要是配置文件的建立与相应命令工具的路径优化
- 安装ZendGuardloader (提高PHP解析效率),并进行加载配置
实验准备
1.将宿主机上的工具包共享出去

2.通过Samba服务将工具包挂载到Linux系统
[root@localhost ~]# mkdir /mnt/tools[root@localhost ~]# smbclient -L //192.168.100.50/Enter SAMBA\root's password: OS=[Windows 10 Enterprise LTSC 2019 17763] Server=[Windows 10 Enterprise LTSC 2019 6.3] Sharename Type Comment --------- ---- ------- IPC$ IPC 远程 IPC share Disk tools Disk Users Disk Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)NetBIOS over TCP disabled -- no workgroup available[root@localhost ~]# mount.cifs //192.168.100.50/tools /mnt/tools/Password for root@//192.168.100.50/tools: [root@localhost ~]# 编译安装Nginx服务
1.将nginx服务源码包解压到"/opt/"目录
[root@localhost ~]# cd /mnt/tools/[root@localhost tools]# lsawstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7 picture.jpgcronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideahahau2018.rar john-1.8.0.tar.gz LNMP[root@localhost tools]# cd LNMP/[root@localhost LNMP]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 php-7.1.20.tar.gz[root@localhost LNMP]# tar zxvf nginx-1.12.2.tar.gz -C /opt/...............//省略解压过程[root@localhost LNMP]#2.安装编译所需工具包
[root@localhost ~]# yum install gcc gcc-c++ pcre-devel zlib-devel -y...........//省略安装过程[root@localhost ~]#3.切换到nginx服务源码包目录,创建一个nginx用户
[root@localhost LNMP]# cd /opt/[root@localhost opt]# lsnginx-1.12.2 rh[root@localhost opt]# cd nginx-1.12.2/[root@localhost nginx-1.12.2]# lsauto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src[root@localhost nginx-1.12.2]# [root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx //-M 不创建家目录[root@localhost nginx-1.12.2]# id nginxuid=1001(nginx) gid=1001(nginx) 组=1001(nginx)[root@localhost nginx-1.12.2]# 4.配置nginx服务
[root@localhost nginx-1.12.2]# ./configure \> --prefix=/usr/local/nginx \ //安装路径> --user=nginx \ //属主> --group=nginx \ //属组> --with-http_stub_status_module //启用统计模块5.编译安装nginx服务
[root@localhost nginx-1.12.2]# make && make install..........//省略过程[root@localhost nginx-1.12.2]#6.在易于系统识别的目录下,建立nginx服务命令的软链接
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ //建立软链接[root@localhost nginx-1.12.2]# nginx -t //配置文件测试nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost nginx-1.12.2]# 7.制作nginx服务管理脚本(任选一种即可)
脚本一:通过"systemctl"命令管理
[root@localhost nginx-1.12.2]# cd /lib/systemd/system[root@localhost system]# vim nginx.service[Unit]Description=nginxAfter=network.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/bin/kill -s HUP $MAINPIDExecStop=/usr/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target[root@localhost system]# chmod 754 nginx.service //添加执行权限[root@localhost system]# systemctl start nginx.service //开启服务[root@localhost system]# netstat -ntap | grep 80 //查看tcp80端口tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 52924/nginx: master [root@localhost system]# [root@localhost system]# systemctl stop firewalld.service //关闭防火墙[root@localhost system]# setenforce 0[root@localhost system]# 脚本二:通过"service"命令管理
[root@nginx nginx-1.12.2]# vim /etc/init.d/nginx#!/bin/bash# chkconfig: - 99 20# description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1esacexit 0[root@nginx nginx-1.12.2]#[root@nginx nginx-1.12.2]# chmod +x /etc/init.d/nginx //添加执行权限[root@nginx nginx-1.12.2]# chkconfig --add nginx //添加让service能识别nginx服务[root@nginx nginx-1.12.2]# [root@nginx nginx-1.12.2]# service nginx start //开启服务[root@nginx nginx-1.12.2]# netstat -ntap | grep 80 //查看tcp80端口tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 58696/nginx: master [root@nginx nginx-1.12.2]#[root@nginx nginx-1.12.2]# systemctl stop firewalld.service //关闭防火墙[root@nginx nginx-1.12.2]# setenforce 0[root@nginx nginx-1.12.2]# 8.用宿主机浏览器访问nginx服务
编译安装MySQL
1.安装编译mysql所需环境包
[root@localhost system]# yum install ncurses ncurses-devel bison cmake -y.........//省略安装过程[root@localhost system]# 2.添加一个mysql用户
[root@localhost system]# useradd -s /sbin/nologin mysql[root@localhost system]#3.将mysql源码包解压到"/opt/"目录下
[root@localhost system]# cd /mnt/tools/LNMP/[root@localhost LNMP]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 php-7.1.20.tar.gz[root@localhost LNMP]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt/............//省略解压过程[root@localhost LNMP]#4.配置mysql服务
[root@localhost LNMP]#cd /opt/mysql-5.7.20/[root@localhost mysql-5.7.20]# lsboost cmd-line-utils Docs libevent mysys source_downloads VERSIONBUILD config.h.cmake Doxyfile-perfschema libmysql mysys_ssl sql VERSION.depclient configure.cmake extra libmysqld packaging sql-common viocmake COPYING include libservices plugin storage winCMakeCache.txt CPackConfig.cmake info_macros.cmake make_dist.cmake rapid strings zlibCMakeFiles CPackSourceConfig.cmake INSTALL Makefile README support-filescmake_install.cmake CTestTestfile.cmake libbinlogevents man regex testclientsCMakeLists.txt dbug libbinlogstandalone mysql-test scripts unittest[root@localhost mysql-5.7.20]# cmake \> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //安装路径> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //定义sock文件连接数据库文件> -DSYSCONFDIR=/etc \ //配置文件目录> -DSYSTEMD_PID_DIR=/usr/local/mysql \ //PID文件目录> -DDEFAULT_CHARSET=utf8 \ //指定字符集,utf8支持中文字符> -DDEFAULT_COLLATION=utf8_general_ci \ 指定字符集默认> -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 //主从参数5.编译安装MySQL服务
[root@localhost mysql-5.7.20]# make && make install...........//省略编译过程[root@localhost mysql-5.7.20]#6.更改数据库目录属主、属组
[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/[root@localhost mysql-5.7.20]# 7.修改配置文件
[root@localhost mysql-5.7.20]# vim /etc/my.cnf[client] //客户端port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql] //客户端port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld] //服务器user = mysql //用户basedir = /usr/local/mysql //设置mysql的安装目录datadir = /usr/local/mysql/data //设置mysql数据库的数据的存放目录port = 3306 //设置3306端口character_set_server=utf8 //中文字符集pid-file = /usr/local/mysql/mysqld.pid //pid文件路径socket = /usr/local/mysql/mysql.sock //sock文件路径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//支持模块8.将mysql相关命令添加本地环境配置中
[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile//将MySQL写到本地环境配置中[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile //设置全局环境配置[root@localhost mysql-5.7.20]# source /etc/profile //重新加载配置文件[root@localhost mysql-5.7.20]#9.初始化数据库
[root@localhost mysql-5.7.20]# cd /usr/local/mysql/[root@localhost mysql]# lsbin COPYING COPYING-test docs include lib man mysql-test README README-test share support-files usr[root@localhost mysql]# bin/mysqld \> --initialize-insecure \ //初始化> --user=mysql \ //用户> --basedir=/usr/local/mysql \ //安装目录> --datadir=/usr/local/mysql/data //数据库数据文件目录10.将MySQL服务配置文件复制到/usr/lib/systemd/system/下便于使用systemctl管理
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /lib/systemd/system///复制[root@localhost mysql]# systemctl start mysqld.service //启动服务[root@localhost mysql]# netstat -ntap | grep 3306 //查看tcp3306端口tcp6 0 0 :::3306 :::* LISTEN 78684/mysqld [root@localhost mysql]# 11.配置MySQL密码
[root@localhost mysql]# mysqladmin -u root -p passwordEnter password: New password: Confirm new password: Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.[root@localhost mysql]#12.尝试登陆MySQL数据库
[root@localhost mysql]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.20 Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quit //退出数据库Bye[root@localhost mysql]# 编译安装PHP
1.安装编译所需环境包
[root@localhost mysql]# yum -y install \> libjpeg libjpeg-devel \ //jpeg图片格式和开发包> libpng libpng-devel \ //png图片和开发包> freetype freetype-devel \ //字体库> libxml2 libxml2-devel \ xml文件库> zlib zlib-devel \ //压缩库> curl curl-devel \ //支持数据文件下载工具> openssl openssl-devel //安全访问连接2.解压源码包
[root@localhost mysql]# cd /mnt/tools/LNMP/[root@localhost LNMP]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 php-7.1.20.tar.gz[root@localhost LNMP]# tar jxvf php-7.1.10.tar.bz2 -C /opt/..........//省略过程[root@localhost LNMP]#3.配置PHP服务
[root@localhost LNMP]# cd /opt/php-7.1.10[root@localhost 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 //gd图像支持图片处理库--with-jpeg-dir //jpeg--with-png-dir //png--with-freetype-dir //字体--with-openssl //安全访问连接--enable-fpm //fpm支持动态请求模块--enable-mbstring //支持多字节的字符串--enable-xml //xml文件--enable-session //session支持会话--enable-ftp //ftp服务--enable-pdo //驱动连接管理--enable-tokenizer //PHP自带函数--enable-zip //zip压缩包4.编译安装
[root@localhost php-7.1.10]# make && make install..........//省略过程[root@localhost php-7.1.10]#5.配置核心配置文件(php.ini核心配置文件,php-fpm.conf进程服务配置文件,www.conf扩展配置文件 )
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini //复制到安装目录lib库中[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini //配置核心配置文件mysqli.default_socket = /usr/local/mysql/mysql.sock //默认连接文件date.timezone = Asia/Shanghai //时区[root@localhost php-7.1.10]# /usr/local/php/bin/php -m[PHP Modules]Corectypecurldate...........//省略部分内容zipzlib[Zend Modules][root@localhost php-7.1.10]# 6.配置及优化FPM模块
[root@localhost php-7.1.10]# cd /usr/local/php/etc/[root@localhost etc]# lspear.conf php-fpm.conf.default php-fpm.d[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf //优化复制默认进程服务配置文件[root@localhost etc]# vim php-fpm.confpid = run/php-fpm.pid //开启fpm.pid进程[root@localhost etc]#[root@localhost etc]# lspear.conf php-fpm.conf php-fpm.conf.default php-fpm.d[root@localhost etc]# cd php-fpm.d/[root@localhost php-fpm.d]# lswww.conf.default[root@localhost php-fpm.d]# cp www.conf.default www.conf //优化复制扩展配置文件[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini [root@localhost php-fpm.d]# netstat -ntap | grep 9000 //查看端口信息tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 87363/php-fpm: mast [root@localhost php-fpm.d]# ln -s /usr/local/php/bin/* /usr/local/bin/ //查看端口信息[root@localhost php-fpm.d]# 7.让Nginx支持PHP功能
[root@localhost php-fpm.d]# vim /usr/local/nginx/conf/nginx.conf //配置nginx配置文件 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; //修改站点路径 include fastcgi_params; }[root@localhost php-fpm.d]# systemctl stop nginx.service //关闭服务[root@localhost php-fpm.d]# systemctl start nginx.service //开启服务[root@localhost php-fpm.d]# 8.创建PHP测试网页
[root@localhost php-fpm.d]# cd /usr/local/nginx/html/[root@localhost html]# ls50x.html index.html[root@localhost html]# mv index.html index.php //修改名称[root@localhost html]# ls50x.html index.php[root@localhost html]# vim index.php [root@localhost html]# 9.用宿主机访问网页
10.进入MySQL数据库创建bbs数据库
[root@localhost html]# mysql -u root -pEnter password: //进入数据库,密码为之前设定的Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.20 Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database bbs; //创建bbs数据库Query OK, 1 row affected (0.01 sec)mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123';//给bbs数据库中的所有表格提升权限,同时创建管理数据库的用户"bbsuser",设置密码。"%"表示可以从所有终端访问Query OK, 0 rows affected, 1 warning (0.02 sec)mysql> grant all on bbs.* to 'bbsuser'@'localhost' identified by 'admin123';Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges; //刷新数据库Query OK, 0 rows affected (0.01 sec)mysql> quit //退出Bye[root@localhost html]#安装Discuz论坛
1.将discuz压缩包解压到"/opt/"目录下
[root@localhost html]# cd /mnt/tools/LNMP/[root@localhost LNMP]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 php-7.1.20.tar.gz[root@localhost LNMP]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt/ //解压............//省略过程[root@localhost LNMP]#2.将解压目录下的upload复制到html站点中,命名为bbs
[root@localhost LNMP]# cd /opt/dir_SC_UTF8/[root@localhost dir_SC_UTF8]# lsreadme upload utility[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs[root@localhost dir_SC_UTF8]#3.进入bbs站点目录,给相关目录文件修改属组和提权
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/[root@localhost bbs]# chown -R root:nginx ./config/[root@localhost bbs]# chown -R root:nginx ./data/[root@localhost bbs]# chown -R root:nginx ./uc_client/[root@localhost bbs]# chown -R root:nginx ./uc_server/[root@localhost bbs]# chmod -R 777 ./config/[root@localhost bbs]# chmod -R 777 ./data/[root@localhost bbs]# chmod -R 777 ./uc_client/[root@localhost bbs]# chmod -R 777 ./uc_server/4.访问192.168.52.133/bbs站点,安装Discuz论坛

5.设置运行环境为全新安装
6.安装数据库
7.成功搭建论坛
8.访问论坛
配置
文件
服务
数据
数据库
目录
编译
支持
环境
过程
模块
路径
管理
端口
动态
命令
字符
工具
用户
论坛
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器机柜功率多大
国家审计署网络安全检查
查询数据库中有哪些存储过程
球球大作战自己创建的服务器
steam为啥连不上服务器
mc 多世界服务器
网络安全知识试题(3)
网安大队开展网络安全宣传
学校网络安全教育培训方案
广西南宁网络安全培训
末日之刃什么时候换服务器
网络安全生产培训总结
芜湖享游网络技术公司官网
湖北计算机网络技术中专
苹果服务器验证
将电脑变成代理服务器
怎么维护公司网络安全
成都郫县棋牌软件开发官方
正牛酒店管理系统服务器
无领导小组网络安全
数据库优化过程中
web服务器web应用程序
amax服务器代理商
自考数据库系统原理完整版doc
第十一代i7服务器直销价格
飞腾arm架构软件开发
mdf不是主数据库文件
服务器UID按钮 系统故障分析
微信云托管操作云开发数据库
保护网络安全 作文