本论坛使用Flarum开源论坛搭建。如果你也想搭建一个这样的论坛,可以参考官方的搭建教程。或者参考下面我搭建的方法
安装ssh并启用密码登陆
假如你购买的服务器没有安装ssh的server端,可以考虑装安装便于后面的步骤(也可以选择不安装)
sudo apt update
sudo apt install openssh-server -y
修改配置文件/etc/ssh/sshd_config,在文件末尾添加
PermitRootLogin yes # 允许root用户登录(生产环境建议设为no)
PasswordAuthentication yes # 启用密码认证
Port 22 # 默认端口(可修改为其他端口增强安全性)
#AllowUsers your_username # 限制允许登录的用户(可选) 如果选的话去掉这行开头的# , your_username改为用户名
然后重启ssh服务
sudo systemctl restart ssh
然后使用 ssh your_username@your_ip 进行连接。其中your_username,指用户名 your_ip 指ip地址。
安装SSL证书
# 使用Certbot自动申请(Apache/Nginx通用)
sudo apt install certbot python3-certbot-apache # Apache
sudo certbot --apache # 按提示操作,自动配置证书
然后会看到
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/www.yourdomain.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/www.yourdomain.com/privkey.pem
This certificate expires on 2026-05-29.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
其中 Certificate is saved at : 和 Key is saved at:为证书和密钥的存储位置
安装Apache并启用mod_rewrite
sudo apt update
sudo apt install -y apache2
sudo systemctl enable --now apache2
编辑默认站点配置,把yourdomain.com替换为你的域名
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerName www.yourdomain.com
ServerAlias yourdomain.com
RewriteEngine On
# 所有 HTTP 请求统一跳转到 https://www 并保留路径与参数
RewriteRule ^ https://www.yourdomain.com%{REQUEST_URI} [R=301,L]
ErrorLog ${APACHE_LOG_DIR}/cainiaohome_80_error.log
CustomLog ${APACHE_LOG_DIR}/cainiaohome_80_access.log combined
</VirtualHost>
/etc/apache2/sites-enabled/000-default-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.yourdomain.com
ServerAlias yourdomain.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/flarum/public
<Directory /var/www/flarum/public>
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
# https 下将裸域 cainiaohome.com 强制跳转到 www(保留路径与参数)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule ^ https://www.yourdomain.com%{REQUEST_URI} [R=301,L]
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/www.yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.yourdomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ErrorLog ${APACHE_LOG_DIR}/cainiaohome_443_error.log
CustomLog ${APACHE_LOG_DIR}/cainiaohome_443_access.log combined
</VirtualHost>
</IfModule>
启用rewrite并重载
sudo a2enmod rewrite
sudo a2enmod rewrite ssl
sudo apache2ctl configtest
sudo systemctl reload apache2
如何遇到问题可通过 sudo apache2ctl -S 查看当前启用的设置,也可以使用sudo a2dissite 000-default.conf和sudo a2ensite 000-default.conf等来关闭或启用对应的设置
安装PHP以及所需扩展
sudo apt update
sudo apt install -y \
php libapache2-mod-php \
php-curl php-xml php-gd php-mbstring php-mysql php-zip
sudo systemctl restart apache2
安装MariaDB
sudo apt update
sudo apt install -y mariadb-server mariadb-client
sudo systemctl enable --now mariadb
sudo mariadb-secure-installation
檢查设置的MariaDB管理员密码是否正确mysql -uroot -p
打开数据库
sudo mysql
创建数据库,YOUR_STRONG_PASSWORD替换为你设置的一个密码
CREATE DATABASE flarum
DEFAULT CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
CREATE USER 'flarum'@'localhost'
IDENTIFIED BY 'YOUR_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON flarum.* TO 'flarum'@'localhost';
FLUSH PRIVILEGES;
检查是否成功
SHOW DATABASES LIKE 'flarum';
SHOW GRANTS FOR 'flarum'@'localhost';
输入exit退出MariaDB
安装 Composer
mkdir /Composer
cd /Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
安装 flarum
sudo mkdir /var/www/flarum
cd /var/www/flarum
composer create-project flarum/flarum:^1.8.0 .
composer require flarum/extension-manager:"*"
设置权限
sudo chown -R www-data:www-data /var/www/flarum
sudo chmod -R 755 /var/www/flarum
然后就可以访问网站,首次访问会进行第一次设置
假如配置完之后发现打不开,显示Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.
可以查看文件的/var/www/flarum/config.php
将 'url' => 'https://xxxx/xxx' 修改为域名地址,(末尾不要加/或者/index.html)
添加中文扩展
cd /var/www/flarum #打开flarum根目录
composer require flarum-lang/chinese-simplified
添加博客功能扩展
cd /var/www/flarum #打开flarum根目录
composer require v17development/flarum-blog