前提
- 域名需要提前解析。
- 注意服务器是否需要备案,如果没备案,会被 x 掉。
- 有一定的 Linux 基础。
环境说明
- Linux Server(本文是用的 CentOS 7.6)
- Apache 或者 Nginx(本文是用的 Nginx)
- PHP 7.1+
- PHP 拓展: curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip, fileinfo
- MySQL 5.6+ 或者 MariaDB 10.0.5+
部署环境安装
更新服务器软件包
yum update -y
安装 Nginx/PHP/MySQL
使用 OneinStack 一键安装,选择好需要的软件以及版本后,复制安装命令到服务器执行就行了,安装过程可能会有点慢,耐心等待就行了。
PHP 扩展中的 fileinfo 一定要勾选
安装 Composer
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
由于 Composer 的服务器在国外,可能导致下载 Flarum 已经依赖包会很慢,所以我们需要更换一下源地址。至于 Composer 是啥,其实就是 PHP 的一个包管理,类似 Java 的 Maven 和 Gradle 工具。
composer config -g repo.packagist composer https://packagist.phpcomposer.com
安装 Flarum
进入到 oneinstack 目录,执行 vhost.sh 脚本新建一个网站
然后进入网站目录执行:
composer create-project flarum/flarum . --stability=beta
然后等待下载 Flarum 以及对应的依赖即可
配置运行
上面其实就已经安装好了 Flarum,但是还需要进一步配置才能正确运行。
创建数据库
登陆 MySQL:
mysql -u root -p密码
创建数据库:
create database 数据库名 character set utf8mb4 collate utf8mb4_bin;
修改 Nginx 配置
进入 Nginx 配置文件目录:
cd /usr/local/nginx/conf/vhost
修改网站的配置文件:
vim xxx.conf
需要修改的地方:
- root:需要在路径后面加上 public,比如我的原本是 root /data/wwwroot/xxx.com;,需要修改为 root /data/wwwroot/xxx.com/public;。
- 引入 Flarum 提供的配置,在 server 大括号中任意位置加上 include /data/wwwroot/xxx/.nginx.conf;,xxx 为网站目录名。比如我的是 include /data/wwwroot/xxx.com/.nginx.conf;
最后的配置示例:
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /usr/local/nginx/conf/ssl/xxx.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/xxx.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name bbs.ryanwang.me;
access_log /data/wwwlogs/xxx.com_nginx.log combined;
index index.html index.htm index.php;
root /data/wwwroot/xxx.com/public;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
include /usr/local/nginx/conf/rewrite/other.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
deny all;
}
include /data/wwwroot/xxx.com/.nginx.conf;
}
检查 Nginx 配置是否有误并重载 Nginx 配置:
nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
nginx -s reload
Flarum 安装引导
xxx 为网站目录名称
chmod -R 777 /data/wwwroot/xxx
进入网站目录:
xxx 为网站目录名称
cd /data/wwwroot/xxx
安装简体中文语言包
composer require csineneo/lang-simplified-chinese
本文摘自Flarum 的安装与配置