Craft CMS 是一个灵活而强大的内容管理系统,在开发人员和内容创作者中广受欢迎。其直观的界面、强大的功能和高度的可定制性使其成为构建和管理网站的首选。
在 Debian 上安装 Craft CMS 12 书虫
步骤 1。使操作系统保持最新状态是维护安全稳定环境的基本步骤。要更新 Debian 12 系统,请打开终端并执行以下命令:
<span class="pln">sudo apt update sudo apt upgrade</span>
这将刷新您的软件包列表,并将所有已安装的软件升级到最新版本。
第2步。创建非 root 用户
以具有 sudo 权限的非 root 用户身份操作是安全性的最佳实践。创建一个新用户并授予他们必要的权限:
<span class="pln">sudo </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">adduser craftcms sudo </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">usermod </span><span class="pun">-</span><span class="pln">aG sudo craftcms su </span><span class="pun">-</span><span class="pln"> craftcms</span>
第 3 步。安装 LAMP 堆栈。
在开始本教程之前,必须在服务器上安装 LAMP 服务器。如果您没有安装 LAMP Stack,您可以按照我们的指南进行操作。
第 4 步。为 Craft CMS 创建数据库
Craft CMS 需要一个 MySQL 数据库来存储其数据。要创建新数据库,请以 root 用户身份登录 MySQL:
<span class="pln">sudo mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
接下来,为 Craft CMS 创建一个新的数据库和用户:
<span class="pln">CREATE DATABASE craftcms</span><span class="pun">;</span><span class="pln"> CREATE USER </span><span class="str">'craftuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-password'</span><span class="pun">;</span><span class="pln"> GRANT ALL PRIVILEGES ON craftcms</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'craftuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span><span class="pln"> EXIT</span><span class="pun">;</span>
第 5 步。使用 Composer 安装 Craft CMS。
Craft CMS 建议使用 Composer(PHP 的依赖管理工具)进行安装。如果您尚未安装 Composer,可以使用以下命令进行安装:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">sS https</span><span class="pun">:</span><span class="com">//getcomposer.org/installer | php</span><span class="pln"> sudo mv composer</span><span class="pun">.</span><span class="pln">phar </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">composer</span>
接下来,导航到 Apache Web 根目录并安装 Craft CMS:
<span class="pln">cd </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html sudo composer create</span><span class="pun">-</span><span class="pln">project craftcms</span><span class="pun">/</span><span class="pln">craft craftcms</span>
第 6 步。为 Craft CMS 配置 Apache
要使 Craft CMS 可通过 Web 访问,您需要配置 Apache。为 Craft CMS 创建一个新的配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">craftcms</span><span class="pun">.</span><span class="pln">conf</span>
在文件中,添加以下配置:
<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln"> ServerAdmin admin@your-domain.com DocumentRoot /var/www/html/craftcms/web ServerName your-domain.com ServerAlias www.your-domain.com </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">html</span><span class="pun">/</span><span class="atn">craftcms</span><span class="pun">/</span><span class="atn">web</span><span class="tag">></span><span class="pln"> Options Indexes FollowSymLinks AllowOverride All Require all granted </span><span class="tag"></Directory></span><span class="pln"> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </span><span class="tag"></VirtualHost></span>
替换“your-domain.com
‘替换为您的域名。保存并关闭文件,然后启用新站点并重写模块:
<span class="pln">sudo a2ensite craftcms sudo a2enmod rewrite sudo systemctl restart apache2</span>
第 7 步。使用 SSL 保护 Craft CMS。
首先,您需要安装 Certbot,这是一个管理 Let’s Encrypt SSL 的客户端包。您可以使用以下命令安装它:
<span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">apache</span>
接下来,您可以使用 Certbot 为您的域获取和安装 SSL 证书。替换您的域名。com
使用您的实际域名:
<span class="pln">sudo certbot </span><span class="pun">--</span><span class="pln">apache </span><span class="pun">-</span><span class="pln">d your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span>
在安装过程中,Certbot 会提示您输入一些基本信息,包括您的电子邮件地址和域名。按照提示完成安装。
第 8 步。配置防火墙。
首先,您需要安装 UFW,这是一个用于管理 Linux 防火墙的用户友好型前端。您可以使用以下命令安装它:
<span class="pln">sudo apt update sudo apt upgrade sudo apt install ufw</span>
现在,我们使用 Apache 设置了一个简单防火墙 (UFW),以允许在默认 Web 端口上对 HTTP 和 HTTPS 进行公共访问:
<span class="pln">sudo ufw allow </span><span class="str">'Apache Full'</span><span class="pln"> sudo ufw allow </span><span class="str">'Apache Secure'</span>
第 9 步。访问 Craft CMS Web 界面
现在,您可以通过在 Web 浏览器中导航到您的域来访问 Craft CMS 安装向导。按照屏幕上的说明完成安装。
感谢您使用本教程在 Debian 12 Bookworm 上安装最新版本的 Craft CMS。如需更多帮助或有用信息,我们建议您查看 Craft CMS 官方网站。