注:Flarum在发文时仍处于beta状态,若有改动,以官方文档为准。
环境配置
php
启用sury软件源以安装php
1 2 3 4 5
| wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg apt install apt-transport-https sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' apt update apt install php7.4 php7.4-fpm php7.4-xml php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-zip php7.4-opcache php7.4-curl
|
mysql
1
| apt install mariadb-server
|
注意,迁移时,要保持双端数据库版本一致
Composer
访问Composer的Download页,复制Command-line installation的命令以安装
执行以下命令使composer全局可用
1
| mv composer.phar /usr/local/bin/composer
|
开始安装
主要参考flarum文档
新建一个空目录,用以下命令安装flarum:
1
| composer create-project flarum/flarum . --stability=beta
|
根据你选择的反代程序,配置URL 重写.
要特别注意文件夹的权限:
1 2
| chmod 775 -R /path/to/directory chown -R www-data:www-data /path/to/directory
|
配置数据库
输入mysql
进行交互:
1 2 3 4
| CREATE DATABASE flarumdb; CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON flarumdb.* To 'newuser'@'localhost'; exit
|
分别是创建数据库,新建用户,授权用户对数据库的访问,退出交互。
在上面的示例中,数据库名称为flarumdb, 用户名/密码为newuser/password
, 根据实际需求修改。
安装Nginx
本文反代以Nginx为例
下面是一个临时配置的示例,看着改路径,证书等会再配,注意root是public文件夹
1 2 3 4 5 6 7 8 9 10 11 12
| server { listen 80; listen [::]:80; root /www/bbs/public; index index.php index.html index.htm; server_name example.com; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } include /www/bbs/.nginx.conf; }
|
保存配置后重启nginx
访问网站,如果权限设置没有问题,会让你指定用户和数据库(相关配置存储在config.php)。
配置证书
acme.sh申请证书,具体过程略。
个人使用的是用Cloudfare DNS API签发Wildcard证书:
(免费域名无权调用Cloudflare API,请使用http方式验证)
1 2 3
| export CF_Key="Your_CloudFlare_API_Key" export CF_Email="Your_CloudFlare_Account_email" acme.sh --issue --dns dns_cf -d "example.tld" -d "*.example.tld"
|
记得installcert时,配置 –reload-cmd “systemctl reload nginx”
配置Nginx
贴上我的Nginx配置示例 (自行修改域名和证书位置):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| server { listen 80 default_server; listen [::]:80 default_server; server_name example.tld; return 301 https://$host$request_uri; } server { listen 80; server_name 1.1.1.1; //改为服务器IP,禁止IP访问 return 403; } server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name example.tld;
ssl_certificate /www/cert/example.cer; ssl_certificate_key /www/cert/example.key;
ssl_protocols TLSv1.3 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ecdh_curve secp521r1:secp384r1; ssl_ciphers EECDH+AESGCM:EECDH+AES256; ssl_session_cache shared:TLS:2m; ssl_buffer_size 4k;
ssl_stapling on; ssl_stapling_verify on; resolver 1.1.1.1 8.8.8.8 valid=300s; resolver_timeout 10s;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
root /www/bbs/public; index index.html index.htm index.php; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } include /www/bbs/.nginx.conf;
location = /sitemap.xml { try_files $uri $uri/ /index.php?$query_string; }
if ($host != 'example.tld' ) { rewrite ^/(.*)$ https://example.tld/$1 permanent; } }
|
插件
进入网站安装目录,使用composer安装。以下是我用的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| composer require fof/spamblock composer require askvortsov/flarum-pwa composer require fof/gamification composer require fof/nightmode composer require askvortsov/flarum-checklist:* composer require fof/moderator-notes composer require fof/user-bio composer require michaelbelgium/flarum-discussion-views composer require clarkwinkelmann/flarum-ext-emojionearea composer require fof/polls composer require fof/best-answer composer require nearata/flarum-ext-no-self-likes composer require askvortsov/flarum-categories composer require fof/user-directory composer require fof/drafts composer require fof/follow-tags composer require fof/frontpage composer require fof/merge-discussions composer require fof/reactions composer require fof/prevent-necrobumping composer require fof/bbcode-details composer require fof/formatting composer require fof/pages composer require v17development/flarum-seo composer require fof/sitemap
composer require ffans/lang-simplified-chinese php flarum cache:clear # 刷新缓存用
|
BBS迁移
参考文章: Migrate flarum to another server
导出原数据库
1
| mysqldump [database] > bak_`date +"%Y%m%d"`.sql
|
导入
1
| mysql [database] < bak.sql
|
打包网站目录,解压到新主机上,配置目录权限。
在新主机上配置环境,新建mysql用户,新建数据库。
导入原数据库,授权用户对数据库的访问。
配置证书与反代。(相关步骤上一章都有提到)
最后按需修改config.php里的变量。
完成!