如何在 Debian 9 上安装基于 Laravel 的 PyroCMS
在此页
- 要求
- 先决条件
- 初始步骤
- 第 1 步 - 安装 PHP 和必要的 PHP 扩展
- 第 2 步 - 安装 MariaDB 并为 PyroCMS 创建数据库
- 第 3 步 - 安装 Acme.sh 客户端并获取 Lets Encrypt 证书(可选)
- 第 4 步 - 安装 NGINX 并为 PyroCMS 配置 NGINX
- 第 5 步 - 安装 Composer
- 第 6 步 - 安装 PyroCMS
- 第 7 步 - 完成 PyroCMS 设置
- 链接
PyroCMS 是一个开源、强大、模块化的 CMS 和开发平台,使用 Laravel 5 构建,可让您更快地构建更好的 Laravel 网站和应用程序。
在本教程中,我们将通过使用 NGINX 作为 Web 服务器、MariaDB 作为数据库服务器,引导您在 Debian 9(stretch)操作系统上完成 PyroCMS 安装过程,并且您可以选择使用 acme.sh 客户端和让加密证书颁发机构添加 SSL 支持。
要求
要安装 PyroCMS,请确保您的系统满足以下要求:
- 至少配置了 1GB RAM 或 Swap
- PHP 7.0 版或更高版本,带有 PDO、cURL、SQLite、OpenSSL、Mbstring、Fileinfo、Tokenizer、GD PHP 扩展。
- MariaDB
- NGINX
先决条件
- 运行 Debian 9 (stretch) 的系统。
- 具有 sudo 权限的非根用户。
初始步骤
检查您的 Debian 系统版本:
lsb_release -ds
# Debian GNU/Linux 9.7 (stretch)
设置时区:
dpkg-reconfigure tzdata
更新您的操作系统包(软件)。这是重要的第一步,因为它确保您拥有操作系统默认软件包的最新更新和安全修复程序:
apt update && apt upgrade -y
安装 Debian 操作系统基本管理所需的一些基本软件包:
apt install -y curl wget vim git sudo unzip socat bash-completion dirmngr apt-transport-https
第 1 步 - 安装 PHP 和必要的 PHP 扩展
下载并安装 PHP 7.0 和所需的 PHP 扩展:
sudo apt install -y php7.0 php7.0-cli php7.0-fpm php7.0-mysql php7.0-curl php7.0-sqlite3 php7.0-mbstring php7.0-gd php7.0-xml
要显示在模块中编译的 PHP,您可以运行:
php -m
ctype
curl
exif
fileinfo
. . .
. . .
检查 PHP 版本:
php --version
# PHP 7.0.33-0+deb9u1 (cli) (built: Dec 7 2018 11:36:49) ( NTS )
# Copyright (c) 1997-2017 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
# with Zend OPcache v7.0.33-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies
PHP-FPM 服务在 Debian 9 系统重启时自动启动和启用,因此无需手动启动和启用。我们可以继续下一步,即数据库安装和设置。
第 2 步 - 安装 MariaDB 并为 PyroCMS 创建数据库
安装 MariaDB:
sudo apt install -y mariadb-server
检查 MariaDB 版本:
mysql --version
# mysql Ver 15.1 Distrib 10.1.37-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
运行 mysql_secure 安装
脚本以提高 MariaDB 安全性并为 MariaDB root
用户设置密码:
sudo mysql_secure_installation
回答每个问题:
Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] Y
New password: your_secure_password
Re-enter new password: your_secure_password
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
以 root 用户身份登录 MariaDB:
sudo mysql -u root -p
# Enter password
创建将用于安装 PyroCMS 的 MariaDB 数据库和用户,并记住凭据:
CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
退出 MariaDB shell:
quit
第 3 步 - 安装 Acme.sh 客户端并获取 Lets Encrypt 证书(可选)
没有必要使用 HTTPS 保护您的网站,但这是保护您的网站流量的好习惯。为了从 Lets Encrypt 获得 SSL 证书,我们将使用 Acme.sh 客户端。 Acme.sh 是一个纯 UNIX shell 软件,用于零依赖地从 Lets Encrypt 获取 SSL 证书。
下载并安装 acme.sh:
sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
./acme.sh --install --accountemail
source ~/.bashrc
cd ~
检查 acme.sh 版本:
acme.sh --version
# v2.8.1
为您的域名/主机名获取 RSA 和 ECC/ECDSA 证书:
# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256
如果你想要假证书进行测试,你可以在上面的命令中添加 --staging
标志。
要列出您颁发的证书,您可以运行:
acme.sh --list
创建一个目录来存储您的证书。我们将使用 /etc/letsencrypt
目录。
mkdir -p /etc/letsencrypt/example.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc
安装/复制证书到 /etc/letsencrypt 目录。
# RSA
acme.sh --install-cert -d example.com \
--cert-file /etc/letsencrypt/example.com/cert.pem \
--key-file /etc/letsencrypt/example.com/private.key \
--fullchain-file /etc/letsencrypt/example.com/fullchain.pem \
--reloadcmd "sudo systemctl reload nginx.service"
# ECC/ECDSA
acme.sh --install-cert -d example.com --ecc \
--cert-file /etc/letsencrypt/example.com_ecc/cert.pem \
--key-file /etc/letsencrypt/example.com_ecc/private.key \
--fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem \
--reloadcmd "sudo systemctl reload nginx.service"
运行上述命令后,您的证书和密钥将位于:
- 对于 RSA:/etc/letsencrypt
/example.com
目录。 - 对于 ECC/ECDSA:/etc/letsencrypt
/example.com_ecc
目录。
所有证书将每 60 天自动更新一次。
获得证书后,退出 root 用户并返回普通 sudo 用户:
exit
第 4 步 - 安装 NGINX 并为 PyroCMS 配置 NGINX
安装 NGINX 网络服务器:
sudo apt install -y nginx
检查 NGINX 版本:
sudo nginx -v
# nginx version: nginx/1.10.3
通过运行以下命令为 PyroCMS 配置 NGINX:
sudo vim /etc/nginx/sites-available/pyro.conf
并使用以下配置填充文件:
server {
listen 80;
listen 443 ssl;
server_name example.com;
index index.php index.html;
root /var/www/pyro/public;
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite ^/(.*)/$ /$1 permanent;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
通过将文件链接到 sites-enabled
目录来激活新的 pyro.conf
配置。
sudo ln -s /etc/nginx/sites-available/pyro.conf /etc/nginx/sites-enabled
检查 NGINX 配置是否存在语法错误:
sudo nginx -t
重新加载 NGINX 服务:
sudo systemctl reload nginx.service
第 5 步 - 安装 Composer
全局安装 PHP 依赖管理器 Composer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
检查 Composer 版本:
composer --version
# Composer version 1.8.4 2019-02-11 10:52:10
第 6 步 - 安装 PyroCMS
创建 PyroCMS 应位于的文档根目录:
sudo mkdir -p /var/www/pyro
将 /var/www/pyro
目录的所有权更改为 [your_user]:
sudo chown -R [your_user]:[your_user] /var/www/pyro
导航到文档根目录:
cd /var/www/pyro
通过 composer
下载 PyroCMS 的最新稳定版本:
composer create-project pyrocms/pyrocms .
将 /var/www/pyro
目录的所有权更改为 www-data
。
sudo chown -R www-data:www-data /var/www/pyro
第 7 步 - 完成 PyroCMS 设置
通过域名或 IP 地址在网络浏览器中访问您的站点,然后按照 PyroCMS 网络安装向导进行操作。

填写完所有必填信息后,您的 PyroCMS 安装就完成了。
链接
- https://pyrocms.com/
- https://github.com/pyrocms/pyrocms