如何在 Ubuntu 22.04 上安装带有 Let's Encrypt SSL 的 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
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 重写模块并使用以下命令重新加载 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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
现在,打开网络浏览器并输入 URL https://flatpress.example.com。您将被重定向到 FlatPress 安装页面:'
现在,单击下一步按钮。您应该看到管理员用户创建页面:
在此提供您的管理员用户名、密码、电子邮件,然后点击下一步按钮。您应该看到以下页面:
单击立即登录按钮。您应该看到以下页面:
提供您的管理员用户名、密码,然后点击登录按钮。您应该看到以下页面:
<跨度>
结论
本教程介绍了如何在 Ubuntu 22.04 上使用 Apache 安装 FlatPress 和 Let's Encrypt SSL。您现在可以使用 FlatPress CMS 创建简单快速的网站和博客。如果您有任何疑问,请随时问我。