Flarum docker安装教程

最近在捣鼓论坛的事情,经过挑选后,选择了Flarum作为论坛软件,本文参考网上资料,给出了Flarum的docker安装教程。

参考资料

docker镜像以及安装脚本:

配置

梳理安装流程,版本配置如下:

  • ubuntu 20.04, windows下还要使用wsl2
  • php 7.4
  • mysql 5.7

后续介绍假设已经有了ubuntu 20.04环境,最后文件路径为

- var
  - www
     - flarum
     - flarum-docker-env
     - script

其中flarum-docker-env和script的仓库地址为:

初始工作目录

home/$USER/var/www

后续默认运行的sh文件均在script目录下,假设工作环境为vscode。

准备工作

换源(备注,如果是服务器的话可以省略这步):

sudo vim /etc/apt/sources.list

在顶部追加

#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#添加清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse

更新

sudo apt-get update
sudo apt-get upgrade

如果产生报错

Could not get lock /var/lib/dpkg/lock-frontend - open

则参考如下资料解决即可

https://askubuntu.com/questions/1109982/e-could-not-get-lock-var-lib-dpkg-lock-frontend-open-11-resource-temporari

安装php + composer

当前目录

home/$USER/var/www

php

sudo apt install php7.4-cli

composer

wget -O composer-setup.php https://getcomposer.org/installer
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

将上述命令写入shell脚本composer.sh中,运行

bash ./script/composer.sh

flarum

当前目录

home/$USER/var/www

安装flarum-beta16依赖的文件

sudo apt-get install php-curl
sudo apt-get install php-dom
sudo apt-get install php-gd
sudo apt-get install php-json
sudo apt-get install php-mbstring
sudo apt-get install php-openssl
sudo apt-get install php-pdo_mysql
sudo apt-get install php-tokenizer
sudo apt-get install php-zip
sudo apt-get install php-mysql

已将上述命令打包,运行脚本即可

bash ./script/php.sh

接下来安装flarum

mkdir flarum && cd flarum
composer create-project flarum/flarum . --stability=beta
cd ..

安装docker以及docker compose

当前目录

home/$USER/var/www

安装docker

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

已将上述命令打包,运行脚本即可

bash ./script/docker.sh

docker composer的安装命令

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

已将上述命令打包,运行脚本即可

bash ./script/docker-compose.sh

安装vscode的docker插件,此时无法识别出docker,运行如下命令

sudo groupadd docker          #添加docker用户组
sudo gpasswd -a $USER docker  #将当前用户添加至docker用户组
newgrp docker                 #更新docker用户组

然后重启服务器即可。

参考资料:

https://blog.csdn.net/qq_36361250/article/details/114769397

https://docs.docker.com/engine/install/linux-postinstall/

安装docker env

当前目录

home/$USER/var/www

运行如下命令

git clone https://github.com/Cobeaver/flarum-docker-env.git
cd flarum-docker-env
ln -s /home/$USER/var/www/flarum www/flarum
cp .env-example .env

备注,ln -s的作用相当于在/home/ubuntu/var/www/flarum-docker-env/www下给出了flarum的快捷方式,最后得到是目录的形式。

修改.env文件中的各个配置,修改路径下

/home/ubuntu/var/www/flarum-docker-env/nginx/conf/conf.d

的三个文件中

default.conf flarum.conf pma.conf

其中example.com为.env中的DOMAIN。

然后运行如下命令

docker-compose up -d 

即可完成安装,后续打开网页进行安装即可。

访问:

http://domain.com

ssl认证

安装完成后,运行

docker  exec  acme.sh --issue -d DOMAIN  --server letsencrypt -w /
docker exec acme.sh --deploy -d DOMAIN --deploy-hook docker

完成配置,其中DOMAIN为域名。

增加重定向(可选):

目标是使得www.domain.com和domain.com均跳转至https://domain.com,修改文件为

/home/$USER/var/www/flarum-docker-env/nginx/conf/conf.d/flarum.conf

添加如下内容:

# add
server {
    listen       80;
    server_name www.domain.com;
    rewrite ^/(.*) https://domain.com/$1 permanent;
}
server {
    listen       80;
    server_name domain.com;
    rewrite ^/(.*) https://domain.com/$1 permanent;
    # rewrite ^(.*)$ https://$host$1 permanent;
}
server {
    listen       443 ssl;
    server_name www.domain.com;
    rewrite ^/(.*) https://domain.com/$1 permanent;
    # rewrite ^(.*)$ https://$host$1 permanent;
}

报错

如果产生如下报错

Warning: file_put_contents(/www/flarum/storage/sessions/0a8KvAcQkJVgHRb0oIGV1n3BRiTfxtH40Az52bOs): failed to open stream: Permission denied in /www/flarum/vendor/illuminate/filesystem/Filesystem.php on line 185
Fatal error: Uncaught Laminas\HttpHandlerRunner\Exception\EmitterException: Unable to emit response; headers already sent in /www/flarum/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php:19 Stack trace: #0 /www/flarum/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitterTrait.php(36): Laminas\HttpHandlerRunner\Exception\EmitterException::forHeadersSent() #1 /www/flarum/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(27): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->assertNoPreviousOutput() #2 /www/flarum/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php(98): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit(Object(Laminas\Diactoros\Response\HtmlResponse)) #3 /www/flarum/vendor/flarum/core/src/Http/Server.php(44): Laminas\HttpHandlerRunner\RequestHandlerRunner->run() #4 /www/flarum/public/index.php(26): Flarum\Http\Server->listen() #5 {main} thrown in /www/flarum/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php on line 19

那么在如下路径下

/home/$USER/var/www

运行

sudo chown -R $USER flarum

版权声明:
作者:admin
链接:https://www.techfm.club/p/30713.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>