本页内容

  • 先决条件
  • 更新系统
  • 安装 Nginx、MariaDB 和 PHP
  • 配置 MariaDB 数据库
  • 安装 Fuel CMS
  • 为 Fuel CMS 配置 Nginx
  • 访问 Fuel CMS Web 界面
  • 使用 Let's Encrypt 保护 Fuel CMS
  • 结语

Fuel CMS 是一款用于网站建设的开源内容管理系统。它基于 CodeIgniter PHP Web 框架,适用于高级 Web 开发。它能帮助用户创建自定义模块,并根据自身需求查看和使用 CMS 部分功能。它提供了一个简单且用户友好的 Web 界面,可从任意设备管理网站。

本文将介绍如何在 Ubuntu 22.04 上使用 Nginx 和 Let's Encrypt SSL 安装 Fuel CMS 系统。

先决条件

  • 一台运行 Ubuntu 22.04 的服务器。
  • 一个已解析到服务器 IP 的域名。
  • 服务器已配置 root 密码。

更新系统

首先,建议将系统软件包更新到最新版本。您可以使用以下命令进行更新:

apt-get update -y
apt-get upgrade -y

所有软件包更新完成后,您可以继续进行下一步。

安装 Nginx、MariaDB 和 PHP

接下来,您需要在系统上安装 Nginx Web 服务器、MariaDB、PHP 以及其他 PHP 扩展。您可以使用以下命令安装所有软件包:

apt-get install nginx mariadb-server php php-cli php-fpm php-mysqli php-curl php-gd php-xml php-common unzip -y

所有软件包安装完成后,请编辑 php.ini 文件,并修改一些默认的 PHP 设置:

nano /etc/php/8.1/fpm/php.ini

修改以下行:

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = UTC

保存并关闭文件,然后重启 PHP-FPM 服务以使更改生效:

systemctl restart php8.1-fpm

配置 MariaDB 数据库

接下来,您需要为 Fuel CMS 创建数据库和用户。首先,使用以下命令登录 MariaDB 控制台:

mysql

连接成功后,使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE fuel;
MariaDB [(none)]> GRANT ALL ON fuel.* TO 'fuel'@'localhost' IDENTIFIED BY 'password';

接下来,刷新权限并退出 MariaDB,使用以下命令:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

至此,MariaDB 已为 Fuel CMS 配置完成。您可以继续进行下一步。

安装 Fuel CMS

首先,使用以下命令创建一个用于存储 Fuel CMS 内容的目录:

mkdir -p /var/www/html/fuel

接下来,进入 Fuel CMS 目录并使用以下命令下载最新版本的 Fuel CMS:

cd /var/www/html/fuel
wget https://github.com/daylightstudio/FUEL-CMS/archive/master.zip

下载完成后,使用以下命令解压下载的文件:

unzip master.zip

接下来,使用以下命令将解压目录中的所有内容移动到当前目录:

mv FUEL-CMS-master/* .

接下来,编辑 database.php 文件并定义您的数据库设置:

nano fuel/application/config/database.php

修改以下行:

$db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'fuel',
        'password' => 'password',
        'database' => 'fuel',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,

接下来,使用以下命令将 Fuel CMS 架构导入 fuel 数据库:

mysql -u fuel -p fuel < fuel/install/fuel_schema.sql

接下来,编辑 MY_fuel.php 并启用管理员登录:

nano fuel/application/config/MY_fuel.php

如下所示,将 FALSE 改为 TRUE:

$config['admin_enabled’] = TRUE;

保存并关闭文件,然后创建会话目录并设置正确的所有权:

mkdir -p /var/lib/php/session
chown -R www-data:www-data /var/lib/php/session
chown -R www-data:www-data /var/www/html/fuel

完成后,您可以继续进行下一步。

为 Fuel CMS 配置 Nginx

首先,创建一个 Nginx 虚拟主机配置文件以托管 Fuel CMS。

nano /etc/nginx/conf.d/fuel.conf

添加以下行:

server {

listen 80;
root /var/www/html/fuel;
index index.php index.html index.htm;
server_name fuelcms.example.com;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass           unix:/var/run/php/php8.1-fpm.sock;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }


}

保存并关闭文件,然后使用以下命令检查 Nginx 是否存在语法错误:

nginx -t

您应该会看到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

接下来,重启 Nginx 服务以使更改生效:

systemctl reload nginx

现在,您可以使用以下命令验证 Nginx 的状态:

systemctl status nginx

您应该会看到以下输出:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-11-20 11:20:17 UTC; 8min ago
       Docs: man:nginx(8)
    Process: 77816 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
   Main PID: 76763 (nginx)
      Tasks: 2 (limit: 2242)
     Memory: 3.0M
        CPU: 62ms
     CGroup: /system.slice/nginx.service
             ??76763 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??77817 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Nov 20 11:20:17 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 20 11:20:17 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.
Nov 20 11:28:14 ubuntu2204 systemd[1]: Reloading A high performance web server and a reverse proxy server...
Nov 20 11:28:14 ubuntu2204 systemd[1]: Reloaded A high performance web server and a reverse proxy server.

至此,Nginx 已配置为托管 Fuel CMS。您现在可以继续访问 Fuel CMS。

访问 Fuel CMS Web 界面

现在,打开您的 Web 浏览器,使用 URL http://fuelcms.example.com/fuel 访问 Fuel CMS。您将被重定向到 Fuel CMS 登录页面:

在 Ubuntu 22.04 上用 Nginx 与 Let's Encrypt 部署 Fuel CMS

输入默认管理员用户名和密码 admin,然后点击“登录”按钮。您应该会看到密码重置界面:

在 Ubuntu 22.04 上用 Nginx 与 Let's Encrypt 部署 Fuel CMS

点击“重置密码”按钮。您应该会看到以下界面:

在 Ubuntu 22.04 上用 Nginx 与 Let's Encrypt 部署 Fuel CMS

输入您的新密码,然后点击“保存”按钮以保存更改。接着,点击“仪表盘”按钮。您应该会在以下页面看到 Fuel CMS 仪表盘:

在 Ubuntu 22.04 上用 Nginx 与 Let's Encrypt 部署 Fuel CMS

使用 Let's Encrypt 保护 Fuel CMS

接下来,您需要安装 Certbot 客户端软件包,以安装并管理 Let's Encrypt SSL。

首先,使用以下命令安装 Certbot:

apt-get install python3-certbot-nginx -y

安装完成后,运行以下命令为您的网站安装 Let's Encrypt SSL:

certbot --nginx -d fuelcms.example.com

系统将要求您提供有效的电子邮件地址并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 
[email protected]


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for fuelcms.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/fuel.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

输入 2 并按 Enter 完成安装。您应该会看到以下输出:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/fuel.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://fuelcms.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=fuelcms.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/fuelcms.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/fuelcms.example.com/privkey.pem
   Your cert will expire on 2023-02-20. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

现在,您的网站已通过 Let's Encrypt SSL 得到保护。您可以使用 URL https://fuelcms.example.com 安全地访问它。

结语

恭喜!您已成功在 Ubuntu 22.04 上使用 Nginx 和 Let's Encrypt SSL 安装了 Fuel CMS。您现在可以试用 Fuel CMS,探索其功能,并开始托管您自己的网站或博客。如果您有任何疑问,欢迎向我提问。