How to Install Grav CMS on Ubuntu 18.04

In 2016, Grav CMS was named the best open source CMS. Also Voted “Best Flat File CMS” in 2017 and 2019. Grav has a powerful API and a sophisticated package manager, making it super flexible. It is written in PHP and its source code Grav is publicly posted on GitHub. The Grav administration plugin is a very simple and intuitive interface. This makes setting up your content creation really nice and easy! In this article we will try to tell you in detail and describe the possibility of installing this CMS on Ubuntu 18.04.

Steps To Be Taken Before Installation

First, you need to check your version of Ubuntu OS. This can be done as follows:

lsb_release -ds
# Ubuntu 18.04 LTS

Next, you must create a new non-root user account with sudo access and then switch to it

adduser Username --gecos "User Name"
usermod -aG sudo usename
su - Username

Set up your necessary time zone

sudo dpkg-reconfigure tzdata

Make sure your system is up to date

sudo apt update && sudo apt upgrade -y

Install unzip

sudo apt install -y unzip

Install PHP and Required PHP Extensions

You can install this using the following command:

sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-xml php7.2-zip php7.2-opcache php-apcu

Install and Configure Nginx

You can install this web server using the following command:

sudo apt install -y nginx

Run sudo vim /etc/nginx/sites-available/grav.conf and configure Nginx for Grav

server {

  listen 80;

  server_name example.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.2-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  }

}

Activate the new grav.conf configuration by linking the file to the sites-enabled directory

sudo ln -s /etc/nginx/sites-available/grav.conf /etc/nginx/sites-enabled/

Then, after activation, you need to test the configuration

sudo nginx -t

Then. restart your Nginx server

sudo systemctl reload nginx.service

Install Grav

Before installation, there is a need to create a document root directory

sudo mkdir -p /var/www/grav

Change the owner of the /var/www/grav directory to username.

sudo chown -R johndoe:johndoe /var/www/grav

Go to the root folder of the document.

cd /var/www/grav

Download the latest Grav zip and unzip it.

wget https://getgrav.org/download/core/grav-admin/1.5.6
unzip 1.5.6
mv grav-admin/* . && mv grav-admin/.* .
rm -rf grav-admin 1.5.6

Change the owner of the /var/www/grav directory to www-data.

sudo chown -R www-data:www-data /var/www/grav

Open http://example.com in your web browser and follow the instructions on the screen. To access your admin panel, add/admin to your url.

Was this article helpful?

Related Articles