Grav is a fast, simple, and flexible flat-file CMS. It has its own Documentation where tells us all the basic information and how to install it step by step. It also provide some useful resources you need.
However there still some barrier to setting a Grav system up from scratch in my own experience, even thought it is not my first time to install it.
First let me introduce my Enviroment: Debian 6.1.69-1 x86_64 GNU/Linux, with PHP 8.2.7 and Apache/2.4.57
1. Download and Extract Grav
The steps to install it:
wget https://getgrav.org/download/core/grav-admin/latest && unzip -j latest
rm latest
This command downloads the latest Grav admin package and extracts it to the grav-admin
folder.
2. Configure Apache Virtual Host
Create a new Apache virtual host configuration file for your Grav site:
vim /etc/apache2/sites-available/yoursite.conf
Copy and paste the following configuration into the file, replacing blog.2volt.cc with your domain:
<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. Obtain SSL Certificate
Run Certbot to obtain SSL certificates for your domain:
sudo certbot --apache --domains blog.2volt.cc
This command will update the Apache configuration file above with SSL settings.
4. Restart Apache
Restart the Apache web server to apply the changes:
sudo systemctl restart apache2
You get the server up. Just open the site: https://blog.2volt.cc.
5. Troubleshoot Session Permission Error
If you encounter the "session_start(): Failed to read session data" error, follow these steps:
5.1. Check Session Save Path Permissions
The session data is typically stored in a directory on the server. Ensure that the directory has the correct permissions for the web server to read and write data.
sudo chmod -R 755 /path/to/session/directory
5.2. Identify Apache User
Identify the user running Apache:
ps aux | egrep '(apache|httpd)'
Look for the user column to identify the Apache user. It's typically 'apache' or 'www-data', but this can vary depending on your server configuration.
5.3. Verify Ownership of Session Directory
Ensure the Apache user owns the session directory:
sudo chown -R www-data:www-data /path/to/session/directory
5.4. Test Your Grav Site
Open your browser and visit your Grav site at https://blog.2volt.cc. If everything is configured correctly, you should see your Grav site up and running. You can visit https://blog.2volt.cc/admin to the administration panel. If it shows 400 File Not Found error, you should check the configuration above, make sure AllowOverride All
is there.