本教程适用于以下操作系统版本
- Ubuntu 24.04 (Noble Numbat)
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 18.04 (Bionic Beaver)
本页内容
- Prerequisites
- Getting Started
- Install Apache, MariaDB, and PHP
- Create a Database for Neos CMS
- Install Neos CMS
- Configure Apache for Neos CMS
- Access Neos CMS
- Secure Neos CMS with Let's Encrypt
- Conclusion
Neos CMS 是一个免费、开源且创新的内容管理系统,可帮助你无需任何编程知识即可管理网站和博客。它简单、安全,并以易用性为设计目标,有助于企业主与用户在多种设备之间协作。它提供了非常实用的功能,包括完整的 Unicode 支持、全面国际化、SEO、内联编辑等。该项目的核心思想是让编辑者尽可能无缝地编辑内容,同时仍能保留其结构。
在本教程中,我们将向你展示如何在 Ubuntu 22.04 服务器上使用 Apache 和 Let's Encrypt SSL 安装 Neos CMS。
Prerequisites
- 一台运行 Ubuntu 22.04 的服务器。
- 一个已指向你服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
Getting Started
首先,运行以下命令将所有系统软件包更新到最新版本:
apt update -y
apt upgrade -y
完成后,你可以进入下一步。
Install Apache, MariaDB, and PHP
接下来,你需要在系统上安装 Apache、MariaDB、PHP 以及其他所需软件包。运行以下命令安装所有这些组件:
apt-get install apache2 mariadb-server php libapache2-mod-php php-common php-mysql php-gmp php-curl php-intl php-mbstring php-xmlrpc php-gd php-bcmath php-xml php-cli php-gmagick php-zip curl unzip git -y
安装完所有软件包后,编辑 php.ini 文件并进行一些修改:
nano /etc/php/8.1/apache2/php.ini
修改以下行:
short_open_tag = On memory_limit = 256M upload_max_filesize = 150M max_execution_time = 360 date.timezone = UTC
保存并关闭文件,然后重启 Apache 服务以使更改生效:
systemctl restart apache2
Create a Database for Neos CMS
首先,你需要设置 MariaDB 的 root 密码并加固安装。你可以使用以下命令来完成:
mysql_secure_installation
按如下所示回答所有问题:
Enter current password for root (enter for none): Set root password? [Y/n]: N 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
完成后,使用以下命令登录 MariaDB:
mysql -u root -p
登录后,使用以下命令为 Neos CMS 创建数据库和用户:
MariaDB [(none)]> CREATE DATABASE neosdb;
MariaDB [(none)]> CREATE USER 'neos'@'localhost' IDENTIFIED BY 'mypassword';
接下来,使用以下命令授予 Neos 数据库全部权限:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON neosdb.* TO 'neos'@'localhost' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
接下来,使用以下命令将数据库字符集更改为 utf8mb4,刷新权限并退出 MariaDB:
MariaDB [(none)]> ALTER DATABASE neosdb charset=utf8mb4;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
接下来,编辑 MariaDB 配置文件并进行一些修改:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
添加以下行:
innodb_file_format = Barracuda innodb_large_prefix = 1 innodb_file_per_table = 1 innodb_default_row_format = dynamic
保存并关闭文件,然后重启 MariaDB 服务以使更改生效:
systemctl restart mariadb
完成后,你可以进入下一步。
Install Neos CMS
开始之前,你需要在系统上安装 Composer。Composer 是一个用于安装 PHP 依赖项的依赖管理器。
运行以下命令安装 Composer:
curl -sS https://getcomposer.org/installer | php
你应该会看到以下输出:
All settings correct for using Composer Downloading... Composer (version 2.4.1) successfully installed to: /root/composer.phar Use it: php composer.phar
接下来,将 Composer 文件移动到系统目录位置:
mv composer.phar /usr/local/bin/composer
接下来,切换到 Apache 网站根目录并使用以下命令下载 Neos CMS:
cd /var/www/html/
git clone https://github.com/neos/neos-base-distribution.git
接下来,重命名下载的目录,并运行 composer 命令安装所有 PHP 依赖项:
mv neos-base-distribution neoscms
cd neoscms
composer install
接下来,为 Neos 目录设置正确的权限和所有权:
chown -R www-data:www-data /var/www/html/neoscms/
chmod -R 755 /var/www/html/neoscms/
完成后,你可以进入下一步。
Configure Apache for Neos CMS
接下来,你需要创建一个 Apache 虚拟主机配置文件来托管 Neos CMS。你可以使用以下命令创建它:
nano /etc/apache2/sites-available/neoscms.conf
添加以下行:
<VirtualHost *:80>
ServerAdmin
[email protected]
DocumentRoot /var/www/html/neoscms/Web
ServerName neos.example.com
<Directory /var/www/html/neoscms/Web/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/neos_error.log
CustomLog ${APACHE_LOG_DIR}/neos_access.log combined
<Directory /var/www/html/neoscms/Web/>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [PT,L]
</Directory>
</VirtualHost>
保存并关闭文件,然后使用以下命令启用虚拟主机并开启 Apache 的 rewrite 模块:
a2ensite neoscms.conf
a2enmod rewrite
接下来,重启 Apache 服务以使更改生效:
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-09-04 08:07:38 UTC; 8s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 22571 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 22577 (apache2)
Tasks: 6 (limit: 4579)
Memory: 14.7M
CPU: 128ms
CGroup: /system.slice/apache2.service
??22577 /usr/sbin/apache2 -k start
??22578 /usr/sbin/apache2 -k start
??22579 /usr/sbin/apache2 -k start
??22580 /usr/sbin/apache2 -k start
??22581 /usr/sbin/apache2 -k start
??22582 /usr/sbin/apache2 -k start
Sep 04 08:07:38 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...
至此,Apache 网站服务器已配置为提供 Neos CMS 服务。你现在可以进入下一步。
Access Neos CMS
现在,打开你的网页浏览器,使用 URL http://neos.example.com 访问 Neos CMS。你将被重定向到以下页面:

点击 Go to setup。你应该会看到以下页面:

提供 SetupPassword.txt 文件中的安装密码,然后点击 Login 按钮。你应该会看到以下页面:

确认所有必需的 PHP 扩展均已安装,然后点击 Next 按钮。你应该会看到以下页面:

填写你的数据库名称、数据库用户名、数据库主机、密码,然后点击 Next 按钮。你应该会看到以下页面:

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


点击 Go to the backend。你应该会看到 Neos CMS 登录页面:

填写你的管理员用户名、密码,然后点击 Login 按钮。你应该在下一页看到 Neos CMS 控制面板:

Secure Neos CMS with Let's Encrypt
使用 Let's Encrypt 免费 SSL 来加固你的网站是个好主意。首先,安装 Certbot 客户端以安装和管理 SSL。你可以使用以下命令安装它:
apt-get install python3-certbot-apache -y
安装完成后,运行以下命令使用 Let's Encrypt SSL 加固你的网站:
certbot --apache -d neos.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 neos.example.com Enabled Apache rewrite module Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/apache2/sites-available/neos-le-ssl.conf Enabled Apache socache_shmcb module Enabled Apache ssl module Deploying Certificate to VirtualHost /etc/apache2/sites-available/neos-le-ssl.conf Enabling available site: /etc/apache2/sites-available/neos-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 并按 Enter 键为你的网站安装 Let's Encrypt SSL:
Enabled Apache rewrite module Redirecting vhost in /etc/apache2/sites-enabled/neos.conf to ssl vhost in /etc/apache2/sites-available/neos-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://neos.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=neos.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/neos.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/neos.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
Conclusion
恭喜!你已经成功在 Ubuntu 22.04 服务器上使用 Apache 和 Let's Encrypt SSL 安装了 Neos CMS。现在你可以通过网页浏览器轻松创建和编辑你的网站。如果你有任何疑问,欢迎随时向我提问。