In this tutorial, we will cover the steps needed for installing Grav CMS on an Ubuntu 18.04 VPS.
Grav is an open-source, fast, and flexible flat-file CMS (or Content Management System) based on and written in PHP. Grav uses a flat-file database for both its back-end and front-end. The main focus is on speed and simplicity instead of on integrated built-in features, which would increase the complexity of the application.
Let’s get started with the installation.
Table of Contents
Prerequisites
- For the purposes of this tutorial, we will use an Ubuntu 18.04 VPS.
- Full SSH root access, or a user with sudo privileges is also required.
Step 1: Connect via SSH and Update
Connect to your server via SSH as the root user using the following command:
ssh root@IP_ADDRESS -p PORT_NUMBER
Remember to replace “IP_ADDRESS” and “PORT_NUMBER” with your server’s respective IP address and SSH port number.
Before starting with the installation, you will need to update your system packages to their latest versions. It’s easy to do, and it won’t take more than a few minutes.
You can do this by running the following command:
sudo apt-get update sudo apt-get upgrade
Once the updates are completed, we can move on to the next step.
Step 2: Installing PHP and required PHP extensions
Before installing Grav, we need to install PHP and all of the required PHP extensions.
First, let’s install the following required packages:
apt install software-properties-common python-software-properties
After the installation is complete, add the Ondřej PPA:
add-apt-repository ppa:ondrej/php
Run the update command again:
apt update
Now we will install PHP7.3 and all required PHP7.3 extensions, by running the following command:
sudo apt install php7.3 php7.3-cli php7.3-fpm php7.3-common php7.3-curl php7.3-gd php7.3-json php7.3-mbstring php7.3-xml php7.3-zip php7.3-opcache php-apcu
You can check the version by running:
php -v
Output:
PHP 7.3.7-2+ubuntu18.04.2+deb.sury.org+1 (cli) (built: Jul 25 2019 11:44:40) ( NTS )
Step 3: Install and Configure Nginx
We will use Nginx as a web server as well as configure server block for a specific domain. We will install Nginx from the official Ubuntu repositories.
To install Nginx run:
sudo apt install nginx
To check the Nginx version, execute this:
sudo nginx -v
The output should look similar to this:
nginx version: nginx/1.14.0 (Ubuntu)
Next, we will configure a new Nginx server block for Grav.
To create a new Grav configuration file, run the following command:
sudo nano /etc/nginx/sites-available/grav.conf
Edit and paste the following Nginx configuration:
NOTE: don’t forget to replace yourdomain.com with your actual registered domain name.
server {
listen 80;
server_name yourdomain.com;
root /var/www/grav;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
To activate the new Grav configuration, we need to create a symbolic link to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/grav.conf /etc/nginx/sites-enabled/
Now, test the Nginx configuration:
nginx -t
If the test is successful, restart the Nginx service:
sudo systemctl restart nginx.service
Step 4: Install Grav
To install Grav, we need to create a document root directory:
sudo mkdir -p /var/www/grav
Next, we will navigate to the /var/www/grav directory and download the latest Grav zip package. You can download the latest Grav zip package from the Grav official website:
cd /var/www/grav
Download the Grav zip package:
wget https://getgrav.org/download/core/grav-admin/1.6.11
Once it is downloaded, we need to extract it:
unzip 1.6.11
Next, we will move all data to the document root directory by running the following commands:
mv grav-admin/* . && mv grav-admin/.* .
To delete the empty grav-admin directory and the Grav package, run:
rm -rf grav-admin/ 1.6.11
Now, we need to change the ownership of the /var/www/grav directory to www-data.
sudo chown -R www-data:www-data /var/www/grav
Now, open http://yourdomain.com in your browser and follow the on-screen instructions. To access the admin dashboard, use http://yourdomain.com/admin as the URL.
That’s all – in this tutorial, we learned how to install Grav on an Ubuntu 18.04 VPS, as well as how to configure nginx server block.
Of course, you don’t have to install Grav on an Ubuntu 18.04 VPS if you use one of our Managed Ubuntu VPS services, in which case you can simply ask our expert Linux admins to install Grav on Ubuntu 18.04 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install Grav on Ubuntu 18.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.