如何在 Debian 9 上使用 NGINX 安装 Fork CMS如何在 Debian 9 上使用 NGINX 安装 Fork CMS如何在 Debian 9 上使用 NGINX 安装 Fork CMS如何在 Debian 9 上使用 NGINX 安装 Fork CMS
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Debian 9 上使用 NGINX 安装 Fork CMS

在此页

  1. 要求
  2. 先决条件
  3. 初始步骤
  4. 第 1 步 - 安装 PHP 和 PHP 扩展
  5. 第 2 步 - 安装 MariaDB 并为 Fork CMS 创建数据库
  6. 第 3 步 - 安装 Acme.sh 客户端并获取 Lets Encrypt 证书(可选)
  7. 第 4 步 - 安装和配置 NGINX
  8. 第 5 步 - 安装 Composer
  9. 第 6 步 - 安装 Fork CMS
  10. 第 7 步 - 完成 Fork CMS 设置
  11. 链接

Fork 是使用 Symfony 组件的易于使用的开源 CMS。它具有直观且用户友好的界面、您可以下载以扩展您的网站的强大应用程序,以及大量精美的主题。在本教程中,我们将使用 Nginx 作为 Web 服务器,使用 MariaDB 作为数据库引擎,在 Debian 9 系统上完成 Fork CMS 安装和设置,您还可以选择使用 Acme.sh 客户端和 Lets Encrypt 证书来保护传输层添加 SSL 支持的权限。

要求

安装和运行 Fork CMS 的要求是:

  • PHP 7.1 或更高版本。
  • 应安装并启用以下 PHP 扩展:cURL、libxml、DOM、SimpleXML、SPL、PDO(带有 MySQL 驱动程序)、mb_string、iconv、GD2 图形库、JSON、PCRE、intl。
  • MySQL 5.0 或更高版本。
  • NGINX 或 Apache with .htaccess、mod_rewrite、mod_expires(可选但推荐)、mod_deflate(可选) 启用。

先决条件

  • 运行 Debian 9 的操作系统。
  • 具有 sudo 权限的非根用户。

初始步骤

检查您的 Debian 版本:

lsb_release -ds
# Debian GNU/Linux 9.9 (stretch)

设置时区:

dpkg-reconfigure tzdata

更新您的操作系统包(软件)。这是重要的第一步,因为它确保您拥有操作系统默认软件包的最新更新和安全修复程序:

apt update && apt upgrade -y

安装 Debian 操作系统基本管理所需的一些基本软件包:

apt install -y curl wget vim git sudo unzip socat bash-completion dirmngr apt-transport-https

第 1 步 - 安装 PHP 和 PHP 扩展

Debian 不在其默认软件存储库中提供最新的 PHP 版本。我们需要添加一个维护第三方存储库的社区。

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

安装 PHP,以及 Fork CMS 所需的 PHP 扩展:

sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-mysql php7.2-curl php7.2-json php7.0-zip php7.2-gd php7.2-xml php7.2-mbstring php7.2-opcache php7.2-intl

要显示在模块中编译的 PHP,您可以运行:

php -m

ctype
curl
exif
fileinfo
. . .
. . .

检查 PHP 版本:

php --version
# PHP 7.2.19-1+0~20190531112637.22+stretch~1.gbp75765b (cli) (built: May 31 2019 11:26:38) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.19-1+0~20190531112637.22+stretch~1.gbp75765b, Copyright (c) 1999-2018, by Zend Technologies

PHP-FPM服务在Debian 9系统重启时自动启动启用,无需手动启动启用。我们可以继续下一步,即数据库安装和设置。

第 2 步 - 安装 MariaDB 并为 Fork CMS 创建数据库

安装 MariaDB 数据库服务器:

sudo apt install -y mariadb-server

检查 MariaDB 版本:

mysql --version
# mysql Ver 15.1 Distrib 10.1.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

运行 mysql_secure installation 脚本以提高 MariaDB 安全性并为 MariaDB 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 用户身份连接到 MariaDB shell:

sudo mysql -u root -p
# Enter password

为 Fork CMS 创建一个空的 MariaDB 数据库和用户并记住凭据:

mysql> CREATE DATABASE dbname;
mysql> GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'mypassword';
mysql> FLUSH PRIVILEGES;

将单词 mypassword 替换为您选择的安全密码。退出 MariaDB:

mysql> exit

将 dbname、username 和 password 替换为您自己的名称。

第 3 步 - 安装 Acme.sh 客户端并获取 Lets Encrypt 证书(可选)

没有必要使用 HTTPS 保护您的网站,但这是保护您的网站流量的好习惯。要从 Lets Encrypt 获取 SSL 证书,我们将使用 Acme.sh 客户端。 Acme.sh 是一个纯 Unix shell 软件,用于零依赖地从 Lets Encrypt 获取 TLS 证书。

下载并安装 acme.sh:

sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
./acme.sh --install --accountemail
source ~/.bashrc
cd ~

检查 acme.sh 版本:

acme.sh --version
# v2.8.2

为您的域/主机名获取 RSA 和 ECC/ECDSA 证书:<br>

# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256

如果你想要假证书进行测试,你可以在上面的命令中添加 --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 天自动更新一次。

获得证书后,从 root 用户退出并返回到普通 sudo 用户:

exit

第 4 步 - 安装和配置 NGINX

安装 NGINX 网络服务器:

sudo apt install -y nginx

检查 NGINX 版本:

sudo nginx -v
# nginx version: nginx/1.10.3

为 Fork CMS 配置 NGINX。运行 sudo vim /etc/nginx/sites-available/fork.conf 并添加以下配置:

server {
    listen 80;
    listen 443 ssl;
root /var/www/fork; index index.php index.html; server_name example.com;

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; location / { # Checks whether the requested url exists as a file $uri or directory $uri/ in the root, else redirect to /index.php. try_files $uri $uri/ @redirects; } location @redirects { rewrite ^ /index.php; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_read_timeout 60; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # Don't pollute the logs with common requests location = /robots.txt { access_log off; log_not_found off; } location = /favicon.ico { access_log off; log_not_found off; } # As Fork CMS has the app_root as doc_root, we need to restrict access to a few things for security purposes! location ~* ^/(composer\..*|vendor\/.*|Procfile$|\.git\/.*|src\/Console.*|.*\.gitignore|\.editorconfig|\.travis.yml|autoload\.php|bower\.json|phpunit\.xml\.dist|.*\.md|app\/logs\/.*|app\/config\/.*|src\/Frontend\/Cache\/CompiledTemplates.*|src\/Frontend\/Cache\/Locale\/.*\.php|src\/Frontend\/Cache\/Navigation\/.*\.php|src\/Frontend\/Cache\/Search\/.*|src\/Backend\/Cache\/CompiledTemplates\/.*|src\/Backend\/Cache\/Locale\/.*\.php)$ { deny all; access_log off; log_not_found off; } # Deny access to dot-files. location ~ /\. { deny all; access_log off; log_not_found off; } }

通过将文件链接到 sites-enabled 目录来激活新的 fork.conf 配置:

sudo ln -s /etc/nginx/sites-available/fork.conf /etc/nginx/sites-enabled

检查 NGINX 配置是否存在语法错误:

sudo nginx -t

重新加载 NGINX 服务:

sudo systemctl reload nginx.service

第 5 步 - 安装 Composer

全局安装 PHP 依赖管理器 Composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

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

检查 Composer 版本:

composer --version
# Composer version 1.8.5 2019-04-09 17:46:47

第 6 步 - 安装 Fork CMS

创建文档根目录。

sudo mkdir -p /var/www/fork

将 /var/www/fork 目录的所有权更改为您当前登录的用户,在我的例子中,此用户名是 johndoe。

sudo chown -R johndoe:johndoe /var/www/fork

在上述命令中将 johndoe 替换为您的登录用户名!从命令行下载 Fork CMS 的最新稳定版本。

cd /var/www/fork
composer create-project forkcms/forkcms .

将 /var/www/fork 目录的所有权更改为 www-data。

sudo chown -R www-data:www-data /var/www/fork

编辑app/config/parameters.yml.dist文件,设置数据库信息。

sudo vim /var/www/fork/app/config/parameters_install.yml

使用您喜欢的网络浏览器,打开您的站点并按照 Fork CMS 安装程序进行操作。按照安装程序进行操作后,您应该可以启动并运行 Fork。要访问 Fork 管理区域,只需将 /private 附加到您的站点 URL。

第 7 步 - 完成 Fork CMS 设置

确保您的服务器满足所有要求并继续:

选择语言,点击下一步:

根据需要选择设置,然后单击下一步:

输入您的数据库设置,然后单击下一步。确保您已经创建了数据库。

创建用户并完成安装:

完成上述所有步骤后,您将看到以下页面:

您已成功安装 Fork CMS。享受您的新 CMS!

链接

  • https://www.fork-cms.com/
  • https://github.com/forkcms/forkcms

©2015-2025 艾丽卡 support@alaica.com