环境准备与依赖检查
部署Discuz!前,需确保Linux服务器满足以下基础环境要求:
1、操作系统:推荐CentOS 7+/Ubuntu 20.04 LTS,兼容性较好。
2、Web服务器:Apache 2.4+ 或 Nginx 1.18+(本文以Nginx为例)。
3、数据库:MySQL 5.7+ 或 MariaDB 10.3+。
4、PHP版本:PHP 7.3及以上,需安装扩展:gd
、pdo_mysql
、openssl
、mbstring
、zip
。
步骤一:安装基础组件
通过包管理器安装所需服务:
CentOS yum install -y nginx mariadb-server php-fpm php-mysqlnd php-gd php-openssl php-mbstring php-zip Ubuntu apt install -y nginx mysql-server php-fpm php-mysql php-gd php-openssl php-mbstring php-zip
步骤二:配置数据库
1、启动MySQL服务并初始化:
systemctl start mysqld systemctl enable mysqld mysql_secure_installation # 按提示设置root密码及安全选项
2、创建Discuz!专用数据库:
CREATE DATABASE discuzdb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER 'discuzuser'@'localhost' IDENTIFIED BY 'StrongPassword123!'; GRANT ALL PRIVILEGES ON discuzdb.* TO 'discuzuser'@'localhost'; FLUSH PRIVILEGES;
步骤三:部署Discuz!程序
1、下载并解压Discuz!源码:
wget https://download.comsenz.com/DiscuzX/3.5/Discuz_X3.5_SC_UTF8_20230520.zip unzip Discuz_X3.5_SC_UTF8_20230520.zip -d /var/www/discuz
2、设置目录权限:
chown -R www-data:www-data /var/www/discuz # Ubuntu用户组 chmod -R 755 /var/www/discuz/config /var/www/discuz/data /var/www/discuz/uc_client/data
步骤四:配置Nginx虚拟主机
编辑/etc/nginx/sites-available/discuz.conf
(Ubuntu)或/etc/nginx/conf.d/discuz.conf
(CentOS):
server { listen 80; server_name yourdomain.com; root /var/www/discuz; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据实际PHP版本调整 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
启用配置并重启服务:
ln -s /etc/nginx/sites-available/discuz.conf /etc/nginx/sites-enabled/ # Ubuntu systemctl restart nginx php-fpm
步骤五:完成安装向导
1、访问http://yourdomain.com
,进入Discuz!安装界面。
2、填写数据库信息:
数据库名:discuzdb
用户名:discuzuser
密码:StrongPassword123!
3、按提示设置管理员账号、站点名称等参数。
安装后优化与安全建议
1、伪静态配置:在Discuz!后台启用URL重写,并同步更新Nginx/Apache规则。
2、HTTPS强制跳转:使用Let’s Encrypt免费证书配置SSL,提升安全性及SEO评分。
3、定期备份:通过cron定时备份数据库(mysqldump
)和站点文件。
常见问题排查
文件权限错误:检查data/
、config/
目录是否可写,确保用户组为www-data
或nginx
。
PHP扩展缺失:执行php -m
验证gd
、pdo_mysql
等扩展是否加载。
数据库连接失败:检查MySQL用户权限及防火墙3306端口放行状态。
引用说明
Discuz! 官方安装文档:https://www.discuz.net
PHP扩展配置指南:https://www.php.net/manual/en
Let’s Encrypt HTTPS配置:https://letsencrypt.org