Grav是一款快速、简单且灵活的平面文件CMS。它有自己的文档,其中包含所有基本信息以及逐步安装的步骤。它还提供一些你可能需要的有用资源。

然而,根据我的经验,即使不是第一次安装,从零开始设置一个Grav系统仍然存在一些障碍。

首先,让我介绍一下我的环境:Debian 6.1.69-1 x86_64 GNU/Linux,使用PHP 8.2.7和Apache/2.4.57。

1. 下载和解压Grav

安装步骤如下:

wget https://getgrav.org/download/core/grav-admin/latest &&  unzip -j latest
rm latest

这个命令会下载最新的Grav管理包并将其解压到grav-admin文件夹中。

2. 配置Apache虚拟主机

为Grav站点创建一个新的Apache虚拟主机配置文件:

vim /etc/apache2/sites-available/yoursite.conf

将以下配置复制并粘贴到文件中,将blog.2volt.cc替换为你的域名:

<VirtualHost *:80>
        ServerName blog.2volt.cc
        DocumentRoot /var/www/html/grav-admin

        RewriteEngine On
        Redirect permanent / https://blog.2volt.cc/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        RewriteCond %{SERVER_NAME} =blog.2volt.cc
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
        ServerName blog.2volt.cc
        DocumentRoot /var/www/html/grav-admin

        RewriteEngine On
        <FilesMatch "\.(?:cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>
        <Directory /var/www/html>
        Options FollowSymLinks
        AllowOverride All
        DirectoryIndex index.php
        Require all granted
        </Directory>
        RequestHeader set X-Forwarded-Proto "https"

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

3. 获取SSL证书

运行Certbot获取你域名的SSL证书:

sudo certbot --apache --domains blog.2volt.cc
这个命令将使用SSL设置更新上述的Apache配置文件。

## 4. 重启 Apache

重启Apache Web服务器以应用更改:

```bash
sudo systemctl restart apache2

现在你的服务器已经启动。只需打开网站:https://blog.2volt.cc。

5. 解决会话权限错误

如果遇到“session_start(): Failed to read session data”错误,请按照以下步骤操作:

5.1. 检查会话保存路径权限

会话数据通常存储在服务器上的一个目录中。确保目录对Web服务器有正确的读写权限。

sudo chmod -R 755 /path/to/session/directory

5.2. 确认Apache用户

识别运行Apache的用户:

ps aux | egrep '(apache|httpd)'

查找用户列以识别Apache用户。通常是 'apache' 或 'www-data',但这可能根据服务器配置而有所不同。

5.3. 验证会话目录的所有权

确保Apache用户拥有会话目录:

sudo chown -R www-data:www-data /path/to/session/directory

5.4. 测试你的Grav站点

在浏览器中打开并访问你的Grav站点,地址为https://blog.2volt.cc。如果一切配置正确,你应该看到你的Grav站点已经运行。你还可以访问https://blog.2volt.cc/admin 进入管理面板。如果显示400文件未找到错误,请检查上述配置,确保 AllowOverride All 已经设置。


Blog Comments powered by Disqus.