本教程适用于以下操作系统版本

  • Ubuntu 20.04 (Focal Fossa)
  • Ubuntu 18.04 (Bionic Beaver)

本页内容

  • 要求
  • 安装 Apache 和 PHP
  • 安装 FlatPress
  • 为 FlatPress 配置 Apache
  • 使用 Let's Encrypt SSL 保护 FlatPress
  • 访问 FlatPress CMS
  • 结论

FlatPress 是一个免费开源且最快的内容管理系统。它使用 PHP 语言编写,对于任何没有数据库访问权限的人来说都是一个很好的工具。它是一款轻量、易于搭建的博客引擎,在社交与通信类别中表现出色。它支持多种语言、插件、主题、小部件等等。

在本教程中,我将介绍如何在 Ubuntu 22.04 服务器上安装 FlatPress。

要求

  • 一台运行 Ubuntu 22.04 的服务器。
  • 一个具有 sudo 权限的非 root 用户。

安装 Apache 和 PHP

默认情况下,PHP 8.1 是 Ubuntu 22.04 中的默认 PHP 版本。但 FlatPress 仅支持 PHP 8.0 版本。因此,你需要将 PHP 仓库添加到你的系统中。你可以使用以下命令添加:

apt install software-properties-common -y
add-apt-repository ppa:ondrej/php

添加仓库后,运行以下命令安装 Apache、PHP 以及所有所需的 PHP 扩展:

apt-get install apache2 php8.0 php8.0-mysql php8.0-curl php8.0-cgi libapache2-mod-php8.0 php8.0-mcrypt php8.0-xmlrpc php8.0-gd php8.0-mbstring php8.0 php8.0-common php8.0-xmlrpc php8.0-soap php8.0-xml php8.0-intl php8.0-cli php8.0-ldap php8.0-zip php8.0-readline php8.0-imap php8.0-tidy php8.0-sql php8.0-intl wget unzip -y

安装完所有软件包后,使用以下命令启动 Apache 服务并使其在开机时自启:

systemctl start apache2
systemctl enable apache2

完成后,你可以进入下一步。

安装 FlatPress

首先,访问 FlatPress 的 Git 仓库,并使用以下命令下载最新版本:

wget https://github.com/flatpressblog/flatpress/archive/1.2.1.zip

接下来,使用以下命令解压下载的文件:

unzip 1.2.1.zip

接下来,使用以下命令将解压出来的目录复制到 Apache 根目录,并赋予适当的权限:

cp -r flatpress-1.2.1 /var/www/html/flatpress
chown -R www-data.www-data /var/www/html/flatpress
chmod -R 775 /var/www/html/flatpress

为 FlatPress 配置 Apache

接下来,你需要为 FlatPress 创建一个 Apache 虚拟主机文件。你可以使用以下命令创建:

nano /etc/apache2/sites-available/flatpress.conf

添加以下行:

<VirtualHost *:80>
     ServerAdmin 
[email protected]

     DocumentRoot /var/www/html/flatpress
     ServerName flatpress.example.com

     <Directory /var/www/html/flatpress/>
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/flatpress_error.log
     CustomLog ${APACHE_LOG_DIR}/flatpress_access.log combined

</VirtualHost>

保存并关闭文件。然后,使用以下命令启用虚拟主机:

a2ensite flatpress

接下来,使用以下命令启用 Apache rewrite 模块并重载 Apache 服务:

a2enmod rewrite
systemctl restart apache2

你还可以使用以下命令检查 Apache 状态:

systemctl status apache2

你应该会看到以下输出:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-11-20 11:37:30 UTC; 6s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 100768 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 100772 (apache2)
      Tasks: 6 (limit: 2242)
     Memory: 14.3M
        CPU: 85ms
     CGroup: /system.slice/apache2.service
             ??100772 /usr/sbin/apache2 -k start
             ??100773 /usr/sbin/apache2 -k start
             ??100774 /usr/sbin/apache2 -k start
             ??100775 /usr/sbin/apache2 -k start
             ??100776 /usr/sbin/apache2 -k start
             ??100777 /usr/sbin/apache2 -k start

Nov 20 11:37:30 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

完成后,你可以进入下一步。

使用 Let's Encrypt SSL 保护 FlatPress

使用 Let's Encrypt SSL 证书来保护你的 FlatPress 站点是个好主意。为此,你需要在系统中安装 Certbot 客户端。Certbot 是一个客户端软件包,可帮助你下载和管理网站上的 SSL 证书。

你可以使用以下命令安装 Certbot:

apt-get install certbot python3-certbot-apache -y

Certbot 客户端安装成功后,运行以下命令为你的网站安装 Let's Encrypt SSL:

certbot --apache -d flatpress.example.com

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

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
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 flatpress.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/flatpress-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/flatpress-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/flatpress-le-ssl.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS,或配置 Nginx 将所有流量重定向到安全的 HTTPS 访问,如以下输出所示:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 键开始该过程。安装完成后,你应该会获得以下输出:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/flatpress.conf to ssl vhost in /etc/apache2/sites-available/flatpress-le-ssl.conf

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/flatpress.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/flatpress.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"
 - 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

至此,你的 FlatPress 站点已通过 Let's Encrypt SSL 得到保护。你现在可以使用 HTTPS 协议安全地访问你的站点。

访问 FlatPress CMS

现在,打开你的网页浏览器并输入网址 https://flatpress.example.com。你将被重定向到 FlatPress 安装页面:

在 Ubuntu 22.04 上安装 FlatPress CMS 并启用 Let's Encrypt SSL

现在,点击 Next 按钮。你应该会看到管理员用户创建页面:

在 Ubuntu 22.04 上安装 FlatPress CMS 并启用 Let's Encrypt SSL

在此处输入你的管理员用户名、密码、电子邮件,然后点击 Next 按钮。你应该会看到以下页面:

在 Ubuntu 22.04 上安装 FlatPress CMS 并启用 Let's Encrypt SSL

点击 Login now 按钮。你应该会看到以下页面:

在 Ubuntu 22.04 上安装 FlatPress CMS 并启用 Let's Encrypt SSL

输入你的管理员用户名、密码,然后点击 Login 按钮。你应该会看到以下页面:

在 Ubuntu 22.04 上安装 FlatPress CMS 并启用 Let's Encrypt SSL

结论

本教程介绍了如何在 Ubuntu 22.04 上使用 Apache 和 Let's Encrypt SSL 安装 FlatPress。你现在可以使用 FlatPress CMS 创建一个简单且快速的网站和博客。如果你有任何问题,随时向我提问。