搭建网站
Discuz! 是一套通用的社区论坛软件系统,您可以通过简单的设置和安装,在互联网上搭建起具备完善功能、高负载能力和可高度定制的论坛服务。
本文介绍在Linux操作系统的ECS实例上,基于LAMP架构搭建Discuz! 论坛。本实践搭建的Discuz! 论坛软件版本及服务器环境如下:
- Discuz! 论坛软件对PHP和MySQL的版本存在依赖关系,安装前请务必参考Discuz! 官网确认依赖信息,避免由于版本不匹配导致Discuz!论坛安装失败。
- 当您使用不同的软件版本时,相关命令和参数可能发生变化,请您根据实际情况进行调整。
- Linux:Linux操作系统,本文以 CentOS 7.8为例。
- Discuz! :论坛网站软件,本文以 Discuz! X3.5为例。
- MySQL:数据库,本文以 MySQL 5.7为例。
- PHP:脚本语言,本文以 PHP 7.0为例。
已有服务


搭建流程

搭建数据库

安装MySQL
本文档以CentOS 7.8操作系统为例安装MySQL 5.7。
- 远程登录云服务器discuz01,填写用户名和密码。
- 安装MySQL。
- 依次执行以下命令,安装MySQL。
wget -i -c https://dev.mysql.com/get/mysql84-community-release-el7-1.noarch.rpm yum -y install mysql84-community-release-el7-1.noarch.rpm yum -y install mysql-community-server --nogpgcheck
- 执行以下命令,验证MySQL的安装版本。
mysql -V
回显如下类似信息:
mysql Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)
- 依次执行以下命令,启动MySQL服务并设置开机自启动。
systemctl start mysqld systemctl enable mysqld
- 查看MySQL运行状态。
systemctl status mysqld.service
回显如下类似信息。

- 执行以下命令,获取安装MySQL时自动设置的root用户密码。
grep 'temporary password' /var/log/mysqld.log
回显如下类似信息。2023-10-31T11:53:08.691748Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys
- 执行以下命令,并按照回显提示信息进行操作,加固MySQL。
mysql_secure_installation
Securing the MySQL server deployment. Enter password for user root: #输入上一步骤中获取的安装MySQL时自动设置的root用户密码 The existing password for the user account root has expired. Please set a new password. New password: #设置新的root用户密码 Re-enter new password: #再次输入密码 The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : N #是否更改root用户密码,输入N ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y Success. All done!
- 依次执行以下命令,安装MySQL。
配置MySQL
- 执行以下命令,再根据提示输入数据库管理员root账号的密码进入数据库。
mysql -u root -p
- 执行以下命令,使用MySQL数据库。
use mysql;
- 执行以下命令,查看用户列表。
select host,user from user;
此命令及以下数据库语句均以分号结尾,请勿忽略。
- 执行以下命令,刷新用户列表并允许所有IP对数据库进行访问。
update user set host='%' where user='root' LIMIT 1;
- 执行以下命令,强制刷新权限。允许同一子网中设置为允许访问的云服务器通过私有IP对MySQL数据库进行访问。
flush privileges;
- 执行以下命令,退出数据库。
quit
- 执行以下命令,重启MySQL服务。
systemctl restart mysqld
- 执行以下命令,设置开机自动启动MySQL服务。
systemctl enable mysqld
- 执行以下命令,关闭防火墙。
systemctl stop firewalld.service
- 重新查看防火墙状态是否为关闭。
systemctl status firewalld
搭建Web环境

安装Web环境
- 将弹性公网IP从云服务器discuz01上解绑,并绑定至云服务器discuz02上。



- 远程登录云服务器discuz02,填写用户名和密码。
- 安装并配置Apache服务器。具体操作,请参见手工搭建LAMP环境(CentOS 7.8 PHP7.0)中的“安装Apache”。
- 安装并配置PHP。具体操作,请参见手工搭建LAMP环境(CentOS 7.8 PHP7.0)中的“安装PHP”。
- 执行以下命令,关闭防火墙。
systemctl stop firewalld.service
- 执行以下命令,重新查看防火墙状态是否为关闭。
systemctl status firewalld
部署网站代码

- 远程登录云服务器discuz02,执行以下命令,安装Discuz软件。
本示例以下载Discuz! X3.5安装包为例,如需下载其他版本,请参见Discuz! 官网。
wget https://gitee.com/Discuz/DiscuzX/releases/download/v3.5-20231001/Discuz_X3.5_SC_UTF8_20231001.zip
- 以上软件来自第三方网站,仅作示例。建议自行获取需要的版本软件,以应对不同需求。
- 上述软件仅为搭建网站指导示例,若搭建的网站做商业用途请自行准备所需软件。
- 执行以下命令,解压Discuz安装包。
unzip Discuz_X3.5_SC_UTF8_20231001.zip
- 执行以下命令,将解压后的“upload”文件夹下的所有文件复制到“var/www/html”路径下。
cp -r upload/* /var/www/html
- 执行以下命令,将写权限赋予给其他用户。
chmod -R 777 /var/www/html
- 在浏览器里输入地址:http://弹性公网IP地址进入安装界面,按照Discuz! 安装向导进行安装。
验证搭建结果
在浏览器中输入:http://弹性公网IP地址/forum.php 可登录论坛主页则说明网站搭建成功。






