On this page

搭建Flarum论坛网站

深度解读Flarum论坛软件搭建全过程 用docker搭建LNMP建站环境

  1. 创建云服务器
  2. 连接云服务器
    1. ssh-keygen命令生成密钥
    2. ssh-copy-id 自动上传公钥
    3. 关闭密码登录
    4. 使用 mosh 提高连接速度
  3. 创建LNMP环境
    1. Docker 安装
    2. 下载LNMP配置文件
    3. 使用Docker安装LNMP环境
  4. 搭建Flarum论坛软件
    1. 修改nginx配置
    2. 下载安装 Composer
    3. 使用Composer安装Flarum论坛软件
    4. 测试Flarum论坛软件

docker lnmp 配置文件

wget  https://github.com/codewhynet/docker-lnmp/archive/refs/heads/main.zip

安装mysql 数据库扩展

 docker exec -it docker_lnmp-8.1-fpm-1  docker-php-ext-install mysqli  pdo_mysql

安装 Composer (composer.phar)

sha256 9a18e1a3aadbcb94c1bafd6c4a98ff931f4b43a456ef48575130466e19f05dd6

wget https://getcomposer.org/download/2.6.5/composer.phar
wget https://getcomposer.org/download/2.6.5/composer.phar.sha256sum

开始安装


apt update
apt install git unzip 7zip

apt install zlib1g-dev libzip-dev
docker-php-ext-install zip
apt-get install -y         libfreetype6-dev         libjpeg62-turbo-dev         libpng-dev 
docker-php-ext-configure gd --with-freetype --with-jpeg 
docker-php-ext-install   gd

composer create-project flarum/flarum .

composer require flarum-lang/chinese-simplified
php flarum cache:clear

nginx/conf.d/snippets/security_web.conf



#过滤url参数
set $URL $request_uri;
if ($URL ~* "root|x0|\[|\]|\$|eval\(|file_put_content|passthru|exec|chroot|chgrp|chown|shell_exec|proc_open|proc_get_status|ini_alter|ini_restore|openlog|syslog|readlink|symlink|popepassthru|stream_socket_server|fsocket|popen"){
return 500;
break;
}

#禁特殊后缀
if ($URL ~* "\.\.|\.asp|\.jsp|\.php|\.aspx|\.dev|\.aspx|\.sql|\.asmx|\.htaccess|\.ini|\.env|\.git|\.project|\.cgi|\.md5|ajax\.js|\.swf") {
  return  500;
  break;
}

#禁空 UA
if ($http_user_agent ~* ^$) {
  return  500;
  break;
}

nginx/conf.d/www.flarum.web.conf

server {

    listen             80;
    listen             [::]:80;

    include            conf.d/snippets/security_web.conf;

    server_name        www.flarum.web;

    set                $base /home/_www_home/www_site/www.flarum.web/src;
    root               $base/public;

    index              index.html index.htm index.php;


    location /assets/ {
        expires        7d;
        root           $base/public/;
    }

    location / {

        include        fastcgi_params;

        fastcgi_pass   docker_lnmp-8.1-fpm-1:9000;
        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param  SCRIPT_NAME /index.php;
        fastcgi_param  PATH_INFO $request_uri;
    }


}

    1  apt install mosh neovim tmux
    2  ufw allow 60000:60009/udp 
    3  nvim /etc/ssh/sshd_config.d/50-cloud-init.conf 
    4  service ssh restart
    5  exit
    6  # Add Docker's official GPG key:
    7  sudo apt-get update
    8  sudo apt-get install ca-certificates curl gnupg
    9  sudo install -m 0755 -d /etc/apt/keyrings
   10  curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
   11  sudo chmod a+r /etc/apt/keyrings/docker.gpg
   12  # Add the repository to Apt sources:
   13  echo   "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
   14  sudo apt-get update	
   15  sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
   16  clear
   17  docker ps
   18  wget  https://github.com/codewhynet/docker-lnmp/archive/refs/heads/main.zip
   19  mkdir /home/_docker_site
   20  cd /home/_docker_site/
   21  unzip  ~/main.zip 
   22  ls
   23  mv docker-lnmp-main/ docker_lnmp
   24  cd docker_lnmp/
   25  bash docker_lnmp.sh 
   26   docker exec -it docker_lnmp-8.1-fpm-1  docker-php-ext-install mysqli  pdo_mysql
   27  ls
   28  cd data/www_site/
   29  ls
   30  wget https://getcomposer.org/download/2.6.5/composer.phar
   31  docker ps
   32  docker exec -it docker_lnmp-8.1-fpm-1  bash
   33  docker ps
   34  docker restart docker_lnmp-8.1-fpm-1
   35  docker exec -it docker_lnmp-8.1-fpm-1  bash
   36  cd ..
   37  cd ..
   38  ls
   39  mkdir config/nginx/conf.d/snippets
   40  nvim config/nginx/conf.d/snippets/security_web.conf
   41  nvim config/nginx/conf.d/www.flarum.web.conf
   42  nvim config/nginx/conf.d/www.flarum.web.conf
   43  docker ps
   44  docker restart docker_lnmp-8.1-fpm-1
   45  docker restart docker_lnmp-nginx-1
   46  ls
   47  cd data/
   48  cd www_site/
   49  ls
   50  cd www.flarum.web/
   51  chown -R www-data:www-data src/
   52  docker ps
   53  docker exec -it docker_lnmp-mysql-1  mysql -uroot -p


    1  apt update
    2  apt install git unzip 7zip
    3  apt install zlib1g-dev libzip-dev
    4  docker-php-ext-install zip
    5  apt-get install -y         libfreetype6-dev         libjpeg62-turbo-dev         libpng-dev 
    6  docker-php-ext-configure gd --with-freetype --with-jpeg 
    7  docker-php-ext-install   gd
    8  cd /home/_www_home/www_site/
    9  ls
   10  mkdir -p www.flarum.web/src
   11  cd www.flarum.web/src/
   12  ls ../../
   13  chmod +x ../../composer.phar 
   14  ../../composer.phar create-project flarum/flarum .
   15  ../../composer.phar  require flarum-lang/chinese-simplified
   16  php flarum cache:clear
   17  ls
   18  php flarum cache:clear
   19  exit
   20  cd /home/_www_home/www_site/www.flarum.web/src/
   21  php flarum cache:clear
   22  php flarum 
   23  clear
   24  exit