本教程适用于以下操作系统版本
- Ubuntu 24.04(Noble Numbat)
- Ubuntu 22.04(Jammy Jellyfish)
- Ubuntu 20.04(Focal Fossa)
- Ubuntu 14.04 LTS(Trusty Tahr)
本页内容
- 准备工作
- 开始之前
- 安装 Apache、PHP 和 MariaDB 服务器
- 为 TYPO3 创建数据库
- 安装 TYPO3 CMS
- 为 TYPO3 创建 Apache 虚拟主机
- 访问 TYPO3 CMS
- 使用 Let's Encrypt 保护 TYPO3
- 总结
TYPO3 是一款免费、开源的企业级内容管理系统。它使用 PHP 编写,将开源代码与可靠性和可扩展性结合在一起。它支持跨平台,可安装到包括 Windows、Linux、macOS 在内的所有主流操作系统上。它专为初学者设计,因此您无需编写代码即可轻松自定义和扩展。它简洁、响应式、适配移动端,是快速搭建并上线网站的绝佳选择。
本教程将向您展示如何在 Ubuntu 22.04 上安装带有 Let's Encrypt SSL 证书的 TYPO3 CMS。
准备工作
- 一台运行 Ubuntu 22.04 的服务器。
- 一个已解析到您服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
开始之前
首先,建议您将系统软件包更新到最新版本。您可以通过运行以下命令来更新所有软件包:
apt update -y
apt upgrade -y
所有软件包更新完成后,您可以继续下一步。
安装 Apache、PHP 和 MariaDB 服务器
接下来,您需要在服务器上安装 Apache Web 服务器、MariaDB、PHP 以及其他 PHP 扩展。您可以使用以下命令将它们全部安装:
apt-get install apache2 mariadb-server php libapache2-mod-php php-common php-gmp php-curl php-intl php-mbstring php-xmlrpc php-mysql php-gd php-xml php-cli php-zip curl git gnupg2 -y
所有软件包安装完成后,请编辑 php.ini 文件并修改一些推荐的设置:
nano /etc/php/8.1/apache2/php.ini
修改以下行:
memory_limit = 256M upload_max_filesize = 100M post_max_size = 100M max_execution_time = 360 max_input_vars = 1500 date.timezone = UTC
保存并关闭文件,然后重启 Apache 服务以使更改生效:
systemctl restart apache2
为 TYPO3 创建数据库
接下来,您需要为 TYPO3 创建一个数据库和用户。首先,使用以下命令登录 MariaDB 命令行:
mysql
登录后,使用以下命令创建数据库和用户:
MariaDB [(none)]> CREATE DATABASE typo3db;
接下来,使用以下命令将全部权限授予 typo3db 数据库:
MariaDB [(none)]> GRANT ALL ON typo3db.* TO 'typo3user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
接下来,使用以下命令刷新权限并退出 MariaDB:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
至此,您的 MariaDB 数据库已配置完成。您可以继续下一步。
安装 TYPO3 CMS
首先,访问 TYPO3 官方网站,并使用 curl 命令下载最新版本的 TYPO3:
curl -L -o typo3_src.tgz https://get.typo3.org/11
下载完成后,使用以下命令解压下载的文件:
tar -xvzf typo3_src.tgz
接下来,将解压后的目录移动到 Apache 网站根目录:
mv typo3_src-11.5.15 /var/www/html/typo3
接下来,使用以下命令为其设置正确的权限:
chown -R www-data:www-data /var/www/html/typo3
chmod -R 775 /var/www/html/typo3
完成后,您可以继续下一步。
为 TYPO3 创建 Apache 虚拟主机
接下来,创建一个 Apache 虚拟主机配置文件来托管 TYPO3 CMS。您可以使用以下命令创建该文件:
nano /etc/apache2/sites-available/typo3.conf
添加以下行:
<VirtualHost *:80>
ServerAdmin
[email protected]
DocumentRoot /var/www/html/typo3
ServerName typo3.example.com
<Directory /var/www/html/typo3>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存并关闭文件,然后使用以下命令启用虚拟主机配置文件和重写模块:
a2ensite typo3.conf
a2enmod rewrite
接下来,重启 Apache 服务以使更改生效:
systemctl restart apache2
至此,Apache Web 服务器已配置好用于提供 TYPO3 服务。您可以继续下一步。
访问 TYPO3 CMS
如果您是在全新服务器上安装 TYPO3,则需要在 TYPO3 网站根目录中创建一个 FIRST_INSTALL 文件。您可以使用以下命令创建它:
touch /var/www/html/typo3/FIRST_INSTALL
chown -R www-data:www-data /var/www/html/typo3/FIRST_INSTALL
现在,打开您的 Web 浏览器,使用 URL http://typo3.example.com 访问 TYPO3。您应该会看到如下页面:


输入您的数据库用户名、密码和主机地址,然后点击“继续”按钮。您应该会看到如下页面:

选择您的 TYPO3 数据库名称,然后点击“继续”按钮。您应该会看到如下页面:

接下来,输入您的管理员用户名、密码和站点名称,然后点击“继续”按钮。您将被重定向到 TYPO3 登录页面:

输入您的管理员用户名和密码,然后点击“登录”按钮。您应该会在以下页面看到 TYPO3 仪表盘:

使用 Let's Encrypt 保护 TYPO3
使用 Let's Encrypt 提供的免费 SSL 来保护您的网站是一个好主意。首先,安装 Certbot 客户端来安装和管理 SSL 证书。您可以使用以下命令安装它:
apt-get install python3-certbot-apache -y
安装完成后,运行以下命令使用 Let's Encrypt SSL 保护您的网站:
certbot --apache -d typo3.example.com
系统会要求您提供电子邮件并接受服务条款,如下所示:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator standalone, Installer None 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 Plugins selected: Authenticator apache, Installer apache Obtaining a new certificate Performing the following challenges: http-01 challenge for typo3.example.com Enabled Apache rewrite module Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/apache2/sites-available/typo3-le-ssl.conf Enabled Apache socache_shmcb module Enabled Apache ssl module Deploying Certificate to VirtualHost /etc/apache2/sites-available/typo3-le-ssl.conf Enabling available site: /etc/apache2/sites-available/typo3-le-ssl.conf
接下来,选择是否将 HTTP 流量重定向到 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 并按下回车键,为您的网站安装 Let's Encrypt SSL 证书:
Enabled Apache rewrite module Redirecting vhost in /etc/apache2/sites-enabled/typo3.conf to ssl vhost in /etc/apache2/sites-available/typo3-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://typo3.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=typo3.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/typo3.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/typo3.example.com/privkey.pem Your cert will expire on 2022-12-07. 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
现在,您可以使用 URL https://typo3.example.com 安全地访问 TYPO3 CMS。
总结
恭喜!您已成功在 Ubuntu 22.04 上安装了 TYPO3 CMS 并使用 Let's Encrypt SSL 对其进行了保护。现在,您可以通过 Web 浏览器轻松创建自己的网站和博客。如果您有任何问题,欢迎随时向我提问。