Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
轻论坛:Flarum 程序安装指南
#1

前言
一直以来,我与 justjavac 共同维护着 Flarum 的中文版本发行。但几年来一直没有写过一篇完整的 Flarum 的安装教程,以至于群里的朋友们遇到安装问题时没有解决方案供参考,给各位带来了不少麻烦,请见谅。

Flarum 英文站: http://flarum.org/Flarum 中文站: http://flarum.org.cn/GitHub: https://github.com/Flarum-Chinese
介绍
环境要求
PHP 5.6+ (mbstring, pdo_mysql, openssl, json, gd, dom, fileinfo)MySQL 5.5+
安装方式
Flarum beta 版本将以 Composer 的方式进行安装,无法通过上传 PHP 代码的传统方式,故安装过程需要登录 SSH 终端。

本文将以 Ubuntu 16.04.3 x64 为例进行。

安装
创建非 root 用户
由于安全原因,不推荐直接在 root 用户下操作,故需先创建一个非 root 用户,并赋予 sudo 权限。

adduser username # 添加用户,替换 username 为你的用户名

# 完成两次密码输入向导
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

# 输入用户信息(允许为空)
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
usermod -aG sudo username # 加入 sudo 用户组,替换 username 为你的用户名

su - username # 切换到 username 用户 *

* 提示:切换到 sudo 用户后,命令前加 sudo 将以管理员权限执行。

安装环境准备
sudo apt-get update && sudo apt-get upgrade # 更新包源及系统依赖

sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/nginx # 添加 NGINX 源

sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php # 添加 PHP 源

sudo apt-get update # 更新源

sudo apt-get install nginx # 安装 NGINX

sudo apt-get install php7.0-fpm php7.0-mysql php7.0-gd php7.0-dom php7.0-mbstring php7.0-curl php7.0-xml # 安装 PHP 7.0 及所需拓展库

sudo apt-get install mysql-server-5.6 # 安装 MySQL 5.6 并设定 root 用户密码

创建 MySQL 用户及数据库
mysql -u root -p # 登录数据库 root 用户

create user 'username'@'localhost'; # 创建数据库用户,替换 username 为你的用户名

set password for 'username'@'localhost' = password('123456'); # 为用户设置密码

create database flarum; # 创建数据库

grant all privileges on flarum.* to 'username'@'localhost'; # 为用户赋予数据库操作权限

flush privileges; # 刷新配置使权限生效

安装 Composer
curl -sS https://getcomposer.org/installer | php

sudo mv composer.phar /usr/local/bin/composer

composer config -g repo.packagist composer https://packagist.phpcomposer.com # 替换中国镜像源 *

* 可选:如果服务器在中国大陆,可使用 Composer 中国全量镜像 为其加速。

安装 Flarum
mkdir -p /var/www/flarum # 创建网站目录

cd /var/www/flarum # 进入目录

composer create-project flarum/flarum . --stability=beta # 安装 Flarum beta 版本

安装目录必须为空目录,请根据提示完成安装,如遇安装失败可根据报错信息重试。

配置 NGINX
vim /etc/nginx/sites-available/default

配置示例:

server {
listen 80;
server_name example.com;
root /var/www/flarum;
index index.php index.html index.htm;

# security config
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
fastcgi_hide_header X-Powered-By;
server_tokens off;

# gizp config
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types application/atom+xml
application/javascript
application/json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
#text/html -- text/html is gzipped by default by nginx
text/plain
text/xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

# php config
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTP_MOD_REWRITE On;
}

# url rewrite
location / { try_files $uri $uri/ /index.php?$query_string; }
location /api { try_files $uri $uri/ /api.php?$query_string; }
location /admin { try_files $uri $uri/ /admin.php?$query_string; }

# expires config
location ~* \.html$ {
expires -1;
}
location ~* \.(?:ico|css|js|gif|bmp|jpe?g|mp4|pdf|mp3|png|svg|ttf|woff|woff2|otf|eot)$ {
access_log off;
expires 30d;
add_header Pragma public;
add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
}

# deny control
location /flarum {
deny all;
return 404;
}
location ~ /assets/.*\.(php)?$ {
deny all;
}

}
* 有关 URL Rewriting 部分参考了 Flarum Documentation

目录权限
此时访问你的网站首页,可以看到安装程序已经正常运行。

但会提示部分目录需要写入权限,否则无法继续完成安装。

可参考以下操作方案:

cd /var/www # 进入网站目录

sudo chown -R username:www-data /var/www/flarum # 更改目录的所有者及所有组 *

* username 为最初创建的非 root 用户,www-data 为 NGINX 及 PHP 进程的默认用户组。

sudo chmod -R g+w,o-rwx flarum/ flarum/assets/ flarum/storage/ # 指定目录权限 *

* g+w: 目录的所有组 (Group) 增加写入权限,o-rwx: 其他用户 (Other) 移除所有权限。

目录权限配置完成后,刷新网页重新进入安装引导。

按照流程填入数据库及管理员信息,即可完成安装。

安装中文语言包
cd /var/www/flarum # 进入网站目录

composer require jsthon/flarum-ext-simplified-chinese # 安装中文语言包拓展

composer dump-autoload --optimize # 优化 Composer 自动加载

* 安装其他 Flarum 拓展插件的操作方法类似。

文末
如果遇到其他问题,可在官方支持论坛发帖。

有关简体中文支持可在 GitHub 中发起 Issue:

https://github.com/Flarum-Chinese/flarum...ed-chinese

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)