如何在Ubuntu 18.04 LTS上安装带有Nginx的Phorum
Phorum 是一个基于PHP和MySQL的开源论坛软件。 在本指南中,我们将引导您逐步完成Ubuntu 18.04 LTS操作系统上的Phorum安装过程,使用Nginx作为Web服务器,MySQL作为数据库,以及acme.sh和Let's Encrypt for HTTPS。
要求
运行Phorum的要求是:
- Nginx的
- PHP 5.2或更高版本
- MySQL 5.0或更高版本
先决条件
- 一个Ubuntu 18.04 LTS操作系统。
- 非root用户
sudo
特权。
初步步骤
检查你的Ubuntu版本:
lsb_release -ds
# Ubuntu 18.04.1 LTS
设置时区:
sudo dpkg-reconfigure tzdata
更新操作系统软件包(软件)。 这是重要的第一步,因为它可确保您拥有适用于操作系统默认软件包的最新更新和安全修复程序:
sudo apt update && sudo apt upgrade -y
安装一些基本管理Ubuntu操作系统所必需的基本软件包:
sudo apt install -y curl wget vim git unzip socat bash-completion apt-transport-https build-essential
第1步 - 安装PHP
安装PHP,以及必要的PHP扩展:
sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-mysql
要显示在模块中编译的PHP,您可以运行:
php -m
ctype
curl
exif
fileinfo
. . .
. . .
检查PHP版本:
php --version
# PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
在Ubuntu 18.04系统上重启时会自动启动并启用PHP-FPM服务,因此无需手动启动和启用它。 我们可以继续下一步,即数据库安装和设置。
第2步 - 安装MySQL并创建数据库
安装MySQL数据库服务器:
sudo apt install -y mysql-server
检查MySQL版本:
mysql --version
# mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
运行mysql_secure installation
用于提高MySQL安全性和设置MySQL密码的脚本 root
用户:
sudo mysql_secure_installation
回答每个问题:
Would you like to setup VALIDATE PASSWORD plugin? N
New password: your_secure_password
Re-enter new password: your_secure_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
以root用户身份连接到MySQL shell:
sudo mysql -u root -p
# Enter password
为Cachet创建一个空的MySQL数据库和用户并记住凭据:
mysql> CREATE DATABASE dbname;
mysql> GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
退出MySQL:
mysql> exit
更换 dbname
, username
和 password
用你自己的名字。
第3步 - 安装 acme.sh
客户端并获取Let的加密证书( 可选 )
无需使用HTTPS保护您的论坛,但保护您的网站流量是一种很好的做法。 为了从Let's Encrypt获取TLS证书,我们将使用acme.sh客户端。 Acme.sh是一个纯UNIX shell软件,用于从具有零依赖关系的Let的加密中获取TLS证书。
下载并安装acme.sh:
sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
./acme.sh --install --accountemail your_email@example.com
source ~/.bashrc
cd ~
检查acme.sh版本:
acme.sh --version
# v2.8.0
获得 RSA 和 ECC / ECDSA 您的域/主机名的证书:
# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256
如果您想要假证书进行测试,可以添加 --staging
上述命令的--staging
标志。
运行上述命令后,您的证书和密钥将位于:
- 对于 RSA :
/home/username/example.com
目录。 - 对于 ECC / ECDSA :
/home/username/example.com_ecc
目录。
要列出您颁发的证书,您可以运行:
acme.sh --list
创建一个目录来存储您的证书。 我们将使用/etc/letsencrypt
目录。
mkdir -p /etc/letsecnrypt/example.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc
安装/复制证书到 在/ etc / letsencrypt 目录 。
# RSA
acme.sh --install-cert -d example.com --cert-file /etc/letsencrypt/example.com/cert.pem --key-file /etc/letsencrypt/example.com/private.key --fullchain-file /etc/letsencrypt/example.com/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"
# ECC/ECDSA
acme.sh --install-cert -d example.com --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"
所有证书将每60天自动续订一次。
获得certs退出root用户并返回正常的sudo用户后:
exit
第4步 - 安装和配置NGINX
安装NGINX:
sudo apt install -y nginx
检查NGINX版本:
sudo nginx -v
# nginx version: nginx/1.14.0 (Ubuntu)
配置NGINX for Phorum。 跑 sudo vim /etc/nginx/sites-available/phorum.conf
并添加以下配置。
server {
listen 80;
listen 443 ssl;
server_name example.com;
root /var/www/phorum;
ssl_certificate /etc/letsencrypt/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/example.com/private.key;
ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/example.com_ecc/private.key;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
激活新的 phorum.conf
通过将文件链接到的配置 sites-enabled
目录:
sudo ln -s /etc/nginx/sites-available/phorum.conf /etc/nginx/sites-enabled
检查 NGINX 语法错误的配置:
sudo nginx -t
重新加载 NGINX 服务:
sudo systemctl reload nginx.service
第4步 - 安装Phorum
为Phorum创建文档根目录:
sudo mkdir -p /var/www/phorum
改变所有权 /var/www/phorum
目录到 [jour_user] :
sudo chown -R [your_user]:[your_user] /var/www/phorum
导航到文档根目录:
cd /var/www/phorum
从中下载最新稳定的Phorum发行版 官方网站 :
wget https://www.phorum.org/downloads/phorum-5.2.23.tar.gz
解压缩下载的存档并将文件移动到文档根目录:
tar xvzf phorum-5.2.23.tar.gz
rm phorum-5.2.23.tar.gz
mv Core-phorum_5_2_23/* . && mv Core-phorum_5_2_23/.* .
rmdir Core-phorum_5_2_23
配置数据库访问:
cp include/db/config.php.sample include/db/config.php
通过编辑配置数据库设置 include/db/config.php
文件:
vim include/db/config.php
改变了所有权 /var/www/phorum
目录到 www-data:
sudo chown -R www-data:www-data /var/www/phorum
要完成安装,请通过访问运行基于Web的安装程序 http://forum.example.com/admin.php
在您的Web浏览器中。