网站服务 / 论坛社区

轻论坛:Flarum 程序部署教程

浅时光 · 8月4日 · 2020年 9198次已读

一、Flarum介绍


Flarum 是一款优雅简洁论坛软件。

让在线交流变得更加轻松愉快。

中文网站:https://flarum.org.cn/

中文社区:https://discuss.flarum.org.cn/

本人社区:https://bbs.dqzboy.com/

  • 如果大家觉得部署LNMP环境比较麻烦的话,我提供与本文档版本一致的LNMP文章来源(Source):https://www.dqzboy.com一键部署脚本,协助大家快速部署LNMP环境,脚本在文章最后下载。

关于有的朋友在安装过程中出现Swap空间不足的情况,大家可文章来源(Source):https://www.dqzboy.com自行百度!!!

二、环境准备


1、文章来源(Source):https://www.dqzboy.com环境要求

  • PHP 5.6+ (mbstring, pdo_mysql, openssl, json, gd, dom, fileinfo)
  • MySQL 5.5+

2、安装命令

yum -y install gcc gcc-c++ libaio make cmake zlib-devel openssl-devel pcre pcre-devel wget git curl lynx lftp mailx mutt rsync ntp net-tools vim lrzsz screen sysstat yum-plugin-security yum-utils createrepo bash-completion zip unzip bzip2 tree tmpwatch pinfo man-pages lshw pciutils gdisk system-storage-manager git  gdbm-devel sqlite-devel

3、关闭防火墙

  • 注意:云服务器一般Firewalld和SELinux都是关闭的,比如阿里云、腾讯云等;如果你是使用的云服务器的话可以忽略此步。
# 检查防火墙是否运行
firewall-cmd --state

# 如果防火墙运行,则执行下面的命令关闭
systemctl stop firewalld && systemctl disable firewalld && systemctl status firewalld

#检查SELinux是否运行,必须关闭
getenforce

#如果SELinux运行,则执行下面的命令将永久其关闭
sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0 && getenforce

三、安装Nginx


  • 安装方式,RPM包安装,版本Nginx1.16.1
  • 注意:我这边将所有的程序包存储在/opt/soft目录下,需要先创建
[[email protected] ~]# mkdir -p /opt/soft && cd /opt/soft
[[email protected] soft]# wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.16.1-1.el7.ngx.x86_64.rpm
[[email protected] soft]# rpm -ivh nginx-1.16.1-1.el7.ngx.x86_64.rpm

#启动服务
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl enable nginx

四、安装数据库


1、下载安装

  • 安装MySQL数据库,安装方式rpm包,版本5.7.30,所需软件包如下:
    • mysql-community-server
    • mysql-community-文章来源(Source):https://www.dqzboy.comclient
    • mysql-com文章来源(Source):https://www.dqzboy.community-common
    • m文章来源(Source):https://www.dqzboy.comysql-community-libs
    • mysql-commun文章来源(Source):https://www.dqzboy.comity-devel
    • mysql-community-libs-compat
  • 官网地址https://downloads.mysql.com/archives/community/
#卸载掉系统默认的mariadb
[[email protected] ~]# rpm -qa|grep mariadb|xargs rpm -e --nodeps

#下载安装程序包
[[email protected] ~]# cd /opt/soft
[[email protected] soft]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
[[email protected] soft]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-common-5.7.30-1.el7.x86_64.rpm
[[email protected] soft]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-libs-5.7.30-1.el7.x86_64.rpm
[[email protected] soft]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
[[email protected] soft]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-devel-5.7.30-1.el7.x86_64.rpm
[[email protected] soft]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-client-5.7.30-1.el7.x86_64.rpm
[[email protected] soft]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/mysql-community-server-5.7.30-1.el7.x86_64.rpm

#执行下面的命令安装MySQL数据库
[[email protected] soft]# yum install mysql-community-*

2、启动程序

[[email protected] soft]# systemctl start mysqld
[[email protected] soft]# systemctl enable mysqld
[[email protected] soft]# systemctl status mysqld

3、创建用户

[[email protected] soft]# cat /var/log/mysqld.log |grep password    #查看默认生成的root用户初始化密码,并使用该密码登入数据库
[[email protected] soft]# mysql -u root -p  # 登录数据库 root 用户

#修改密码策略
mysql> set global validate_password_policy=0;
mysql> set global validate_password_mixed_case_count=0;
mysql> set global validate_password_number_count=3;
mysql> set global validate_password_special_char_count=0;
mysql> set global validate_password_length=3;

#重置root用户密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'dqz123456';


#创建flarum用户
mysql> CREATE USER 'flarum'@'localhost' IDENTIFIED BY 'dqz123456'; # 创建数据库用户

mysql> create database flarum;  # 创建数据库

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

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

五、安装PHP74


  • 安装方式YUM安装,版本7.4
[[email protected] ~]# yum -y install epel-release
[[email protected] ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[[email protected] ~]# yum --enablerepo=remi install php74-php php74-php-pear php74-php-bcmath php74-php-pecl-jsond-devel php74-php-mysqlnd php74-php-gd php74-php-common php74-php-fpm php74-php-intl php74-php-cli php74-php php74-php-xml php74-php-opcache php74-php-pecl-apcu php74-php-pdo php74-php-gmp php74-php-process php74-php-pecl-imagick php74-php-devel php74-php-mbstring php74-php-zip php74-php-ldap php74-php-imap php74-php-pecl-mcrypt

[[email protected] ~]# vim /etc/profile
export PATH=/opt/remi/php74/root/usr/bin:$PATH

[[email protected] ~]# ln -sv /opt/remi/php74/root/bin/php /usr/bin/php
[[email protected] ~]# php -version
  • 更改运行用户为Nginx
[[email protected] ~]# vim /etc/opt/remi/php74/php-fpm.d/www.conf
轻论坛:Flarum 程序部署教程-浅时光博客
#启动服务
[[email protected] ~]# systemctl start php74-php-fpm.service
[[email protected] ~]# systemctl enable php74-php-fpm.service

#通过ps -ef查看php的运行用户
[[email protected] ~]# ps -ef|grep php-fpm

六、安装 Composer


  • 创建普通用户并授权和设置密码
[[email protected] ~]# useradd flarum
[[email protected] ~]# echo dqz123456|passwd --stdin flarum

#添加普通用户可提权为root权限
[[email protected] ~]# visudo
flarum  ALL=(ALL)       NOPASSWD:ALL
轻论坛:Flarum 程序部署教程-浅时光博客
[[email protected] ~]# su - flarum
[[email protected] ~]$ php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" 
[[email protected] ~]$ php composer-setup.php 
[[email protected] ~]$ php -r "unlink('composer-setup.php');"
[[email protected] ~]$ sudo mv composer.phar /usr/local/bin/composer
  • 由于 Composer 的服务器在国外,可能导致下载 Flarum 已经依赖包会很慢,所以我们需要更换一下源地址。
#替换为国内源
[[email protected] ~]$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer
[[email protected] ~]$ composer config -gl	#查看当前使用的全局源
轻论坛:Flarum 程序部署教程-浅时光博客
文章来源(Source):https://www.dqzboy.com

七、安装 Flarum


# 创建网站目录
[[email protected] ~]$ sudo mkdir -p /www/flarum
[[email protected] ~]$ cd /www/flarum
[[email protected] flarum]$ sudo chown -R flarum. /www/flarum/

#安装目录必须为空目录,请根据提示完成安装,如遇安装失败可根据报错信息重试。
[[email protected] flarum]$ composer create-project flarum/flarum . --stability=beta
轻论坛:Flarum 程序部署教程-浅时光博客

八、修改目录权限


  • 可参考以下操作方案:
[[email protected] ~]$ cd /www # 进入网站目录

[[email protected] www]$ sudo chown -R flarum:nginx /www/flarum  #更改目录的属主及属组
# flarum为最初创建的用户,nginx为 NGINX 及 PHP 进程的默认用户组。

[[email protected] www]$ sudo chmod -R g+w,o-rwx flarum/ flarum/public/assets/ flarum/storage/

九、配置Nginx


不加SSL证书的Nginx配置如下:

[[email protected] ~]$ sudo vim /etc/nginx/conf.d/flarum.conf
server {
  listen 80;
  #网站域名
  server_name  bbs.dqzboy.com;
  #flarum项目存储目录
  root /www/flarum/public;
  index index.html index.htm index.php;

  location ~ [^/]\.php(/|$) {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_connect_timeout  300;
        fastcgi_send_timeout  300;
        fastcgi_read_timeout  300;
        include        fastcgi_params;
  }
 
  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 /www/flarum/.nginx.conf;    #注意这里引入flarum默认自带的Nginx配置;注意写成自己的程序存储目录
}

加了SSL证书的Nginx配置如下:

[[email protected] ~]$ sudo vim /etc/nginx/conf.d/flarum.conf
server {
  listen   443  ssl;
  server_name  bbs.dqzboy.com;    #网站域名
  ssl_certificate  1_xxxxx.crt;        #证书存放路径,如果是在nginx主目录下,则直接写证书文件名称即可,下面key文件也是如此
  ssl_certificate_key  2_xxxxx.key;
  ssl_session_timeout 5m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  ssl_prefer_server_ciphers on;
  root /www/flarum/public;    #flarum项目存储目录
  index index.html index.htm index.php;

  location ~ [^/]\.php(/|$) {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_connect_timeout  300;
        fastcgi_send_timeout  300;
        fastcgi_read_timeout  300;
        include        fastcgi_params;
  }
 
  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 /www/flarum/.nginx.conf;    #注意这里引入flarum默认自带的Nginx配置;注意写成自己的程序存储目录
}

server {
    listen 80;
    #填写绑定证书的域名
    server_name bbs.dqzboy.com; 
    #把http的域名请求转成https
    #rewrite ^(.*)$ https://$host$1 permanent;
    return      301 https://$server_name$request_uri;
}

十、访问网站


轻论坛:Flarum 程序部署教程-浅时光博客
轻论坛:Flarum 程序部署教程-浅时光博客

十一、安装中文包


[[email protected] ~]$ cd /www/flarum  #进入网站目录
[[email protected] flarum]$ composer require littlegolden/flarum-lang-simplified-chinese #安装中文语言包拓展
  • 启用中文插件,web界面等人管理员账号
轻论坛:Flarum 程序部署教程-浅时光博客
轻论坛:Flarum 程序部署教程-浅时光博客
轻论坛:Flarum 程序部署教程-浅时光博客

脚本使用方文章来源(Source):https://www.dqzboy.com

1、注意:脚本执行完成后,php运行用户也会自动更改Nginx用户;最后会将MySQL默认root登入密码显示出来

2、将脚本上传到服务器中,并赋予执行权限,然后通过以下命令执行;注意:必须用root用户执行

chmod +x lnmp_install
./lnmp_install

脚本部署的版本如下:

1、Nginx:1.18.0

2、MySQL:5.7.30

3、PHP:php74






文件名称:LNMP环境一键部署脚本

更新日期:2020-08-04

文件大小:24k

广

点击下载

轻论坛:Flarum 程序部署教程-浅时光博客
1 条回应
  1. 青春未知2020-8-30 · 22:21

    这个论坛属实好看

本站已安全运行: | 耗时 0.442 秒 | 查询 112 次 | 内存 19.94 MB