实验所需包:
https://gitee.com/lengyingxi/discuz
一、安装 Nginx 服务
前提配置好yum本地源
关闭防火墙:
[root@discuz ~]# systemctl stop firewalld
[root@discuz ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@discuz ~]# vi /etc/selinux/config
[root@discuz ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@discuz ~]#
安装依赖包:
[root@discuz ~]# yum -y install pcre-devel zlib-devel gcc gcc-c++ make
创建运行用户:
root@discuz ~]# useradd -M -s /sbin/nologin nginx
编译安装:
[root@discuz ~]# cd /opt/
[root@discuz opt]# ll
总用量 960
-rw-r--r--. 1 root root 980831 3月 1 01:35 nginx-1.12.0.tar.gz
[root@discuz opt]#
[root@discuz opt]# tar zxvf nginx-1.12.0.tar.gz
[root@discuz opt]# ll
总用量 960
drwxr-xr-x. 8 1001 1001 158 4月 12 2017 nginx-1.12.0
-rw-r--r--. 1 root root 980831 3月 1 01:35 nginx-1.12.0.tar.gz
[root@discuz opt]#
[root@discuz nginx-1.12.0]# cd nginx-1.12.0
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
[root@discuz nginx-1.12.0]# make -j 2
[root@discuz nginx-1.12.0]# make install
优化路径:
[root@discuz nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
添加nginx系统服务:
[root@discuz nginx-1.12.0]# cat /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=£orking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/ki11 -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@discuz nginx-1.12.0]#
[root@discuz nginx-1.12.0]# chmod 754 /lib/systemd/system/nginx.service
[root@discuz nginx-1.12.0]# systemctl start nginx.service
[root@discuz nginx-1.12.0]# systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@discuz nginx-1.12.0]#
二、安装 MySQL 服务
安装mysql环境依赖包:
root@discuz ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
创建运行用户:
[root@discuz ~]# useradd -M -s /sbin/nologin mysql
[root@discuz ~]#
编译安装:
[root@discuz ~]# cd /opt/
[root@discuz opt]# ll
总用量 48656
drwxr-xr-x. 36 7161 31415 4096 9月 13 2017 mysql-5.7.20
-rw-r--r--. 1 root root 48833145 3月 1 01:43 mysql-boost-5.7.20.tar.gz
drwxr-xr-x. 9 mysql mysql 186 3月 1 01:37 nginx-1.12.0
-rw-r--r--. 1 root root 980831 3月 1 01:35 nginx-1.12.0.tar.gz
[root@discuz opt]#
[root@discuz opt]# cd mysql-5.7.20/
[root@discuz 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
[root@discuz mysql-5.7.20]# make -j 4
# 长达20分钟的编译人麻木了可以去刷一会抖音等待
[root@discuz mysql-5.7.20]# make install
修改mysql配置文件:
[root@discuz mysql-5.7.20]# cat /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
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
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
[root@discuz mysql-5.7.20]#
更改mysql安装目录和配置文件的属主属组
[root@discuz mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql/
[root@discuz mysql-5.7.20]# chown mysql.mysql /etc/my.cnf
[root@discuz mysql-5.7.20]#
设置路径环境变量:
[root@discuz mysql-5.7.20]# echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@discuz mysql-5.7.20]# source /etc/profile
初始化数据库:
[root@discuz ~]# cd /usr/local/mysql/bin/
[root@discuz bin]#
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
添加mysql系统服务:
[root@discuz bin]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@discuz bin]#
[root@discuz bin]# systemctl daemon-reload
[root@discuz bin]# systemctl start mysqld.service
[root@discuz bin]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@discuz bin]#
[root@discuz bin]# netstat -anpt | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 37724/mysqld
[root@discuz bin]#
修改mysql登录密码:
[root@discuz bin]# mysqladmin -u root -p password "123123"
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@discuz bin]#
授权远程登录:
[root@discuz bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant all privileges on *.* to 'root'@'%' identified by '123123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye
[root@discuz bin]#
三、安装配置 PHP 解析环境
安装依赖环境包:
[root@discuz ~]#
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
编译安装:
[root@discuz ~]# cd /opt/
[root@discuz opt]# tar jxvf php-7.1.10.tar.bz2
# 如果解压失败安装yum -y install bzip2 即可
[root@discuz opt]# ll
总用量 63376
drwxr-xr-x. 38 7161 31415 4096 3月 1 03:25 mysql-5.7.20
-rw-r--r--. 1 root root 48833145 3月 1 01:43 mysql-boost-5.7.20.tar.gz
drwxr-xr-x. 9 mysql mysql 186 3月 1 01:37 nginx-1.12.0
-rw-r--r--. 1 root root 980831 3月 1 01:35 nginx-1.12.0.tar.gz
drwxrwxr-x. 15 nginx nginx 4096 9月 27 2017 php-7.1.10
-rw-r--r--. 1 root root 15069098 3月 1 03:40 php-7.1.10.tar.bz2
[root@discuz opt]#
[root@discuz opt]# cd php-7.1.10
[root@discuz 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
[root@discuz php-7.1.10]# make
[root@discuz php-7.1.10]# make install
路径优化:
[root@discuz php-7.1.10]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@discuz php-7.1.10]# ln -s /usr/local/php/sbin/* /usr/local/sbin/
[root@discuz php-7.1.10]#
介绍:
php有三个配置文件:
php.ini——主配置文件
php-fpm.conf——进程服务配置文件
www. conf——扩展配置文件
#调整主配置文件
[root@discuz php-7.1.10]# cp /opt/php-7.1.10/php.ini-development /usr/local/php/php.ini
[root@discuz php-7.1.10]#vim /usr/local/php/php.ini
--1170行--修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939行--取消注释,修改
date.timezone = Asia/Shanghai
[root@discuz php-7.1.10]# php -m
#验证安装的模块
[root@discuz php-7.1.10]# cd /usr/local/php/etc/
[root@discuz etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@discuz etc]#
[root@discuz etc]# cp php-fpm.conf.default php-fpm.conf
[root@discuz etc]# vim php-fpm.conf
--17行--去掉";"注释
pid = run/php-fpm.pid
#调整扩展配置文件:
[root@discuz php-fpm.d]# vim www.conf
user = nginx #23和24行
#更改用户名
group = nginx
pm.max_children = 50 #107行左右
#fpm支持的最大进程数
pm.start_servers = 20
#启动时开启的进程数
pm.min_spare_servers = 5
#空闲时最小保留的进程数
pm.max_spare_servers = 20
#最大空闲进程数
启动php-fpm
[root@discuz php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@discuz php-fpm.d]# netstat -anpt | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 44829/php-fpm: mast
[root@discuz php-fpm.d]#
配置nginx支持php解析:
[root@discuz php-fpm.d]# vim /usr/local/nginx/conf/nginx.conf
--65行--取消注释,修改
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;
#将/scripts修改为nginx的工作目录
include fastcgi_params;
}
[root@discuz php-fpm.d]# systemctl restart nginx.service
验证php测试页:
[root@discuz php-fpm.d]# cat /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
[root@discuz php-fpm.d]#
[root@discuz php-fpm.d]# nginx
killall -3 nginx
nginx
#若有问题,终止进程后重新启动
浏览器访问
http://192.168.88.188/index.php
验证数据库工作是否正常:
[root@discuz bin]# mysqladmin -u root -p password "123123"
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be inse cure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@discuz bin]#
[root@discuz bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database bbs;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on bbs.* to 'bbsuser'@'%' 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> quit
Bye
[root@discuz bin]#
替换原来的测试页内容:
[root@discuz bin]# cat /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.126.15','bbsuser','admin123');
if($link) echo "<h1>Success~</h1>";
else echo "Fail~";
?>
[root@discuz bin]#
# 浏览器访问
http://192.168.88.188/index.php
四、部署 Discuz 社区论坛 Web 应用
解压Discuz:
[root@discuz ~]# cd /opt/
[root@discuz opt]#
[root@discuz opt]# unzip Discuz_X3.4_SC_UTF8_20230210.zip -d /opt/dis
[root@discuz opt]# ll
总用量 75068
drwxr-xr-x. 4 root root 105 3月 1 04:47 dis
-rw-r--r--. 1 root root 11969306 3月 1 04:45 Discuz_X3.4_SC_UTF8_20230210.zip
drwxr-xr-x. 38 7161 31415 4096 3月 1 03:25 mysql-5.7.20
-rw-r--r--. 1 root root 48833145 3月 1 01:43 mysql-boost-5.7.20.tar.gz
drwxr-xr-x. 9 mysql mysql 186 3月 1 01:37 nginx-1.12.0
-rw-r--r--. 1 root root 980831 3月 1 01:35 nginx-1.12.0.tar.gz
drwxrwxr-x. 18 nginx nginx 4096 3月 1 03:44 php-7.1.10
-rw-r--r--. 1 root root 15069098 3月 1 03:40 php-7.1.10.tar.bz2
[root@discuz opt]#
调整论坛目录的权限:
[root@discuz opt]# cd dis/
[root@discuz dis]# cp -r upload/ /usr/local/nginx/html/bbs/
[root@discuz dis]# cd /usr/local/nginx/html/bbs/
[root@discuz bbs]# chown -R root:nginx ./config/
[root@discuz bbs]# chown -R root:nginx ./data/
[root@discuz bbs]# chown -R root:nginx ./uc_client/
[root@discuz bbs]# chown -R root:nginx ./uc_server/
[root@discuz bbs]# chmod -R 777 ./config/
[root@discuz bbs]# chmod -R 777 ./data/
[root@discuz bbs]# chmod -R 777 ./uc_client/
[root@discuz bbs]# chmod -R 777 ./uc_server/
[root@discuz bbs]#
论坛页面访问:
# 论坛页面访问:http://192.168.88.188/bbs/install/index.php
# http://192.168.88.188/bbs/index.php
数据库服务器: localhost。本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字: bbs
数据库用户名: bbsuser
数据库密码: admin123
管理员账号:admin
管理员密码:admin123
访问主页:
http://192.168.88.188/bbs/index.php
后台管理页面
http://192.168.88.188/bbs/admin.php