Overview
Grav is a flat-file CMS, that is very quick and doesn't require a database. You can install it on your webserver or local Ubuntu machine.
Our Grav CMS set-up requires Apache and PHP. If you don't have these running on your Linux machine, please follow the steps in our article on how to do this. Don't forget, Grav doesn't require a database, so you can skip the MySQL section.
So, since we have Apache and PHP installed, it is now time to set-up our Grav CMS website.
Choose a domain name
I am going to create a Grav CMS website using the domain name mysite.dev. You can use any domain name if doing this on your local machine, otherwise use your own registered domain name.
Throughout this article replace mysite.dev with your own domain name.
Connect to your web server
Open a terminal. If using a remote server, connect via ssh, entering your server IP address.
ssh root@192.123.4.56
Edit hosts file
If you are using Grav CMS on your local Ubuntu machine then you also need to configure your hosts file so that our web browser knows where to look for our site.
sudo nano /etc/hosts
Add the following to the hosts file so Ubuntu knows that when looking up mysite.dev it should visit your machine's local ip address.
127.0.1.1 mysite.dev
Let's save our changes.
ctrl + o to save, then ctrl + x to exit nano.
Download Grav CMS
cd /var/www/html
wget https://getgrav.org/download/core/grav-admin/latest -O grav-admin.zip
Unzip Grav. Replace mysite with your own directory name.
unzip grav-admin.zip && mv grav-admin mysite
Set file and folder permissions
If doing this on a hosted webserver, set the owner to www-data. Otherwise set it to your own username.
chown -R www-data /var/www/html/mysite
Set the group to www-data.
chgrp -R www-data /var/www/html/mysite
Set the permissions.
chmod -R 755 /var/www/html/mysite
Create a website configuration file
Make sure you replace mysite.dev with your own website domain name!
sudo nano /etc/apache2/sites-available/mysite.dev.conf
Paste in the following configuration, changing any directory paths to reflect your set-up.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mysite.dev
DocumentRoot /var/www/html/mysite
<Directory /var/www/html/mysite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mysite_error.log
CustomLog ${APACHE_LOG_DIR}/mysite_access.log combined
</VirtualHost>
Enable mod_rewrite
Grav needs to be able to able to rewrite incoming requests.
So instead of URL's like /products.php?id=3271, we can use /products/3271. Which is much cleaner.
sudo a2enmod rewrite
Enable your website
sudo a2ensite mysite.dev.conf
Let's restart apache for our changes to take effect.
sudo systemctl reload apache2
Check that it worked
Navigate to https://mysite.dev/admin.
You should see the Grav CMS admin page.