在本页
- 先决条件
- 第 1 步 - 配置防火墙
- 第 2 步 - 安装 Nginx
- 第 3 步 - 安装 PHP 及扩展
- 第 4 步 - 安装并配置 MySQL 服务器
- 第 5 步 - 安装 Composer
- 第 6 步 - 安装 Neos CMS
- 第 7 步 - 配置 SELinux 权限
- 第 8 步 - 安装并配置 SSL
- 第 9 步 - 配置 Nginx 和 PHP 配置 PHP-FPM 配置 Nginx
- 第 10 步 - 完成 Neos 安装
- 结论
- 配置 PHP-FPM
- 配置 Nginx
Neos 是一个免费的开源内容管理系统(CMS),可让您无需编写代码即可轻松构建复杂的网站。您可以使用它创建博客、新闻网站、作品集页面或公司网站。它提供丰富的功能集,例如内联编辑、支持在单一安装中托管多个网站、内置 SEO 工具、人类可读的 URL、插件管理器、设备预览,并支持多种模板。它支持现代技术,例如 REST API、JSON、GraphQL 和 oEmbed。
在本教程中,您将学习如何在运行 Rocky Linux 8 操作系统的服务器上安装 Neos CMS。
先决条件
- 一台运行 Rocky Linux 8 的服务器。
- 一个具有 sudo 权限的非 root 用户。
- 确保所有内容都已更新。$ sudo dnf update
- 安装基本的实用工具包。其中一些可能已经安装。$ sudo dnf install wget curl nano unzip yum-utils -y
一台运行 Rocky Linux 8 的服务器。
一个具有 sudo 权限的非 root 用户。
确保所有内容都已更新。
$ sudo dnf update
安装基本的实用工具包。其中一些可能已经安装。
$ sudo dnf install wget curl nano unzip yum-utils -y
第 1 步 - 配置防火墙
第一步是配置防火墙。Rocky Linux 使用 Firewalld 防火墙。检查防火墙的状态。
$ sudo firewall-cmd --state
running
防火墙使用不同的区域(zone),我们将使用默认的 public 区域。列出防火墙上所有处于活动状态的服务和端口。
$ sudo firewall-cmd --permanent --list-services
它应显示如下输出。
cockpit dhcpv6-client ssh
允许 HTTP 和 HTTPS 端口。
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
再次检查防火墙的状态。
$ sudo firewall-cmd --permanent --list-services
您应该看到类似的输出。
cockpit dhcpv6-client http https ssh
重新加载防火墙以使更改生效。
$ sudo firewall-cmd --reload
第 2 步 - 安装 Nginx
Rocky Linux 自带较旧版本的 Nginx。您需要下载官方 Nginx 存储库以安装最新版本。
创建并打开 /etc/yum.repos.d/nginx.repo 文件,以创建官方 Nginx 存储库。
$ sudo nano /etc/yum.repos.d/nginx.repo
将以下代码粘贴到其中。
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
安装 Nginx。
$ sudo dnf install nginx
验证安装。
$ nginx -v
nginx version: nginx/1.20.2
启用并启动 Nginx 服务。
$ sudo systemctl enable nginx --now
第 3 步 - 安装 PHP 及扩展
对于本教程,我们需要使用 Remi 的存储库安装最新版本的 PHP。第一步是获取 Epel 存储库。
$ sudo dnf install epel-release
接下来,安装 Remi 存储库。
$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
检查可用的 PHP 流(stream)。
$ dnf module list php -y
Last metadata expiration check: 0:00:12 ago on Fri 03 Dec 2021 09:39:32 AM UTC.
Rocky Linux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Remi's Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
php remi-8.1 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
默认版本是 7.2。启用 Remi 的 PHP 8.0 存储库。
$ sudo dnf module reset php
$ sudo dnf module enable php:remi-8.0
接下来,安装 PHP 及其 Neos 所需的扩展,以及 ImageMagick。
$ sudo dnf install php-fpm php-mbstring php-xml php-curl php-mysqlnd php-zip php-cli php-imagick ImageMagick php-intl
验证安装。
$ php --version
PHP 8.0.14 (cli) (built: Dec 16 2021 03:01:07) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies
第 4 步 - 安装并配置 MySQL 服务器
我们将使用 MySQL 数据库来存储数据。Rocky Linux 的 Appstream 存储库自带最新版本的 MySQL。
安装 MySQL。
$ sudo dnf install mysql-server
启用并启动 MySQL 服务。
$ sudo systemctl enable mysqld --now
保护 MySQL 安装的安全。
$ sudo mysql_secure_installation
在第一步中,系统会询问您是否要设置 Validate Password Plugin(密码验证插件),您可以使用它来测试 MySQL 密码的强度。选择 Y 继续。下一步会要求您选择密码验证级别。选择 2,这是最强的级别,它要求您的密码长度至少为八个字符,并包含大写字母、小写字母、数字和特殊字符的组合。
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
下一步会要求您选择 root 密码。请选择一个满足密码验证插件要求的强密码。再下一步,系统会询问您是否继续使用所选密码。按 y 继续。
Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
对于以下所有提示,均按 Y 然后按 ENTER 键,以删除匿名用户和测试数据库、禁用 root 登录并加载新设置的规则。
...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
...
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
进入 MySQL shell。输入您的 root 密码以继续。
$ mysql -u root -p
创建 neos 用户。确保密码满足之前设置的要求。
mysql> CREATE USER 'neos'@'localhost' IDENTIFIED BY 'Your_password2';
创建 neosdb 数据库。
mysql> CREATE DATABASE neosdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
授予该用户在 neosdb 数据库上的权限。
mysql> GRANT ALL PRIVILEGES ON neosdb.* TO 'neos'@'localhost';
退出 Shell。
mysql> exit
第 5 步 - 安装 Composer
Composer 是 PHP 的依赖管理工具,Neos CMS 运行需要它。
下载 Composer 安装程序脚本。
$ curl -sS https://getcomposer.org/installer -o composer-setup.php
运行以下命令以验证安装程序。
$ HASH=`curl -sS https://composer.github.io/installer.sig`
$ echo $HASH
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
上述命令会获取安装程序的哈希值,并将其与您下载的脚本进行匹配。如果安装程序可以安全运行,您应该会看到如下输出。
Installer verified
安装 Composer。
$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
通过检查其版本来验证安装。
$ composer --version
Composer version 2.2.3 2021-12-31 12:18:53
第 6 步 - 安装 Neos CMS
创建一个用于安装 Neos 的根目录。
$ sudo mkdir -p /var/www/neos
将该根目录的所有权更改为当前登录的用户。
$ sudo chown -R $USER:$USER /var/www/neos
切换到该根目录。
$ cd /var/www/neos
使用 Composer 安装 Neos 及其依赖项。
$ composer create-project --no-dev neos/neos-base-distribution .
不要忘记命令末尾的点号,它告诉 Composer 将其安装在当前目录中。安装过程中您可能会看到以下警告。输入 y 继续。安装不会因此受到影响。
- Installing neos/composer-plugin (2.1.3): Extracting archive
neos/composer-plugin contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "neos/composer-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
- Installing composer/package-versions-deprecated (1.11.99.4): Extracting archive
composer/package-versions-deprecated contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "composer/package-versions-deprecated" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
将该根目录的所有权更改为 nginx 。
$ sudo ./flow core:setfilepermissions $USER nginx nginx
将当前登录的用户添加到 nginx 组。
$ sudo usermod -a -G nginx $USER
目前就这些内容。我们将在稍后执行剩余的配置。
第 7 步 - 配置 SELinux 权限
使用 SELinux 的 chcon 命令更改从 /var/www/neos 目录提供的 Web 内容的文件安全上下文。
$ sudo chcon -t httpd_sys_content_t /var/www/neos -R
$ sudo chcon -t httpd_sys_rw_content_t /var/www/neos -R
配置 SELinux 以允许 Neos CMS 的网络连接。
$ sudo setsebool -P httpd_can_network_connect on
第 8 步 - 安装并配置 SSL
要使用 Let's Encrypt 安装 SSL 证书,我们需要下载 Certbot 工具。安装 Certbot 需要 Epel 存储库,但由于我们在本教程前面已经安装了它,因此可以跳过此步骤。
安装 Certbot。
$ sudo dnf install certbot
停止 Nginx 服务器,因为它会干扰 Certbot 工具。
$ sudo systemctl stop nginx
生成 SSL 证书。
$ sudo certbot certonly --standalone --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m
[email protected]
-d neos.example.com
上述命令会将证书下载到您服务器上的 /etc/letsencrypt/live/neos.example.com 目录。
生成 Diffie-Hellman 组证书。
$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
为 Let's Encrypt 自动续期创建一个 challenge Web 根目录。
$ sudo mkdir -p /var/lib/letsencrypt
创建一个 Cron 作业来续期 SSL。它将每天运行以检查证书并在需要时续期。为此,首先创建文件 /etc/cron.daily/certbot-renew 并打开以进行编辑。
$ sudo nano /etc/cron.daily/certbot-renew
粘贴以下代码。
#!/bin/sh
certbot renew --cert-name neos.example.com --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl reload nginx"
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
更改该任务文件的权限以使其可执行。
$ sudo chmod +x /etc/cron.daily/certbot-renew
第 9 步 - 配置 Nginx 和 PHP
配置 PHP-FPM
打开文件 /etc/php-fpm.d/www.conf 。
$ sudo nano /etc/php-fpm.d/www.conf
我们需要将 PHP 进程的 Unix 用户/组设置为 nginx 。在文件中找到 user=www-data 和 group=www-data 这两行,并将它们更改为 nginx 。
...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
...
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
启动 PHP 服务。
$ sudo systemctl start php-fpm
配置 Nginx
创建并打开文件 /etc/nginx/conf.d/neos.conf 以进行编辑。
$ sudo nano /etc/nginx/conf.d/neos.conf
将以下代码粘贴到其中。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name neos.example.com;
access_log /var/log/nginx/neos.access.log;
error_log /var/log/nginx/neos.error.log;
# SSL
ssl_certificate /etc/letsencrypt/live/neos.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/neos.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/neos.example.com/chain.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
ssl_stapling on;
ssl_stapling_verify on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
resolver 8.8.8.8;
root /var/www/neos/Web/;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Pass PHP Scripts To FastCGI Server
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/run/php-fpm/www.sock; # Depends On The PHP Version
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param FLOW_REWRITEURLS 1;
fastcgi_param FLOW_CONTEXT Production;
fastcgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
fastcgi_param X-Forwarded-Port $proxy_port;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_NAME $http_host;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
try_files $uri =404;
}
location ~ /_Resources/ {
access_log off;
log_not_found off;
expires max;
if (!-f $request_filename) {
rewrite "/_Resources/Persistent/([a-z0-9]{40})/.+\.(.+)" /_Resources/Persistent/$1.$2 break;
rewrite "/_Resources/Persistent(?>/[a-z0-9]{5}){8}/([a-f0-9]{40})/.+\.(.+)" /_Resources/Persistent/$1.$2 break;
}
}
}
# enforce HTTPS
server {
listen 80;
listen [::]:80;
server_name neos.example.com;
return 301 https://$host$request_uri;
}
请注意,Nginx 配置中使用的根目录是 /var/www/neos/Web/ ,而不是 /var/www/neos/ 。
完成后,按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
打开文件 /etc/nginx/nginx.conf 以进行编辑。
$ sudo nano /etc/nginx/nginx.conf
在 include /etc/nginx/conf.d/*.conf; 这一行之前添加以下行。
server_names_hash_bucket_size 64;
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
验证 Nginx 配置文件的语法。
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重启 Nginx 服务以使新配置生效。
$ sudo systemctl restart nginx
第 10 步 - 完成 Neos 安装
在浏览器中打开 URL https://neos.example.com ,您将看到如下设置界面。

点击 Go to setup 按钮继续。您将被重定向到登录界面。

在终端中运行以下命令以获取您的密码。
$ cat /var/www/neos/Data/SetupPassword.txt
The setup password is:
SCPUYmmQ
After you successfully logged in, this file is automatically deleted for security reasons.
Make sure to save the setup password for later use.
输入密码并点击 Login 继续。Neos 将检查 PHP 图像库。

点击 Next 继续。系统会要求您输入数据库凭据。输入在第 4 步中创建的凭据。凭据验证通过后,屏幕上将显示 Connection established 消息。

点击 Next 继续。系统会要求您设置管理员帐户。填写您的详细信息。

点击 Next 继续。接下来,系统会要求您选择是导入 Demo 站点还是从头创建一个站点。如果要从头创建新站点,必须填写两个框。例如,如果要创建新闻站点,请按给出的内容填写这些框。请记住,如果从头开始,站点上将没有 CSS,您必须自己编写。
Package Name: Neos.exampleNews
Site Name: exampleNews
对于本教程,我们将选择 Demo 站点。要导入演示站点,请将所有字段留空。

点击 Next 继续。您将看到设置完成界面。

点击 Go to the backend 按钮以打开控制面板的登录界面。输入您的用户名和密码,然后点击 Login 以打开管理面板。

由于我们导入了演示站点,第一步是删除 Try me 页面,该页面允许任何人设置具有编辑网站权限的后端帐户。
从左侧边栏切换到 Try me 页面,然后点击下面截图中高亮显示的 Delete 按钮。

点击 Published - Live 按钮右侧的橙色箭头以打开下拉菜单,然后点击 Publish all 以保存更改。

您的 Neos CMS 安装已准备就绪,可以使用了。
结论
在本教程中,您使用 LEMP 堆栈在基于 Rocky Linux 8 的服务器上安装并配置了 Neos CMS。如果您有任何问题,请在下面的评论中发布。