• Get In Touch
November 18, 2016

Install and Configure Grav CMS on Ubuntu 16.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

There are many powerful, open source CMS applications available such as Joomla, WordPress and Drupal. But this will require a significant amount of your time for installation, configuration and management.

Grav is a file based, fast, simple and flexible web content management system application written in PHP and uses Twig as a template engine. Grav does not use a database to store content, it uses text files and markdown files to store the content. It is a free and open source application which is available from GitHub. Grav handles the content in an easy way, so it be simple for a developer.

Grav uses several external technologies such as twig for templating, YAML for configuration, Symfony Console for CLI interface, Symfony Console for CLI interface, Parsedown for fast markdown and Markdown for content creation.

In this tutorial, we will learn how to install and setup Grav CMS on Ubuntu 16.04 server.

Requirements

  • A server running Ubuntu-16.04 on your system.
  • A non-root user with sudo privileges setup on your server.

Update the System

Before starting, you will need to update the system’s package repository database with the latest version. You can do this with the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

You will also need to install some necessary packages to your system.

You can install them with the following command:

sudo apt-get install software-properties-common git nano curl build-essential libyaml-dev

Once your package repository is up-to-date, you can proceed with installing PHP and other required modules.

Installing PHP and Required Modules

Next, you will need to install the latest stable version of PHP and other PHP modules.
You can install it with the following command:

sudo apt-get install php7.0 php7.0-fpm php7.0-cli php7.0-gd php7.0-mbstring php-pear php7.0-curl php7.0-dev php7.0-opcache php7.0-xml

Once installation is completed, you will need to install the apcu PHP extension.

You can install it with the pecl command:

sudo pecl install apcu

Next, create a apcu.ini file inside /etc/php/7.0/mods-available directory to enable apcu extension:

sudo nano /etc/php/7.0/mods-available/apcu.ini

Add the following line:

extension=apcu.so

Next, create a symlink of apcu.ini file:

sudo ln -s /etc/php/7.0/mods-available/apcu.ini /etc/php/7.0/fpm/conf.d/20-apcu.ini
sudo ln -s /etc/php/7.0/mods-available/apcu.ini /etc/php/7.0/cli/conf.d/20-apcu.ini

Next, you will also need to install the Yaml PHP extension to increase performance.
You can install it with the following command:

sudo pecl install yaml-2.0.0

Next, create a yaml.ini file to enable yaml extension:

sudo nano /etc/php/7.0/mods-available/yaml.ini

Add the following line:

extension=yaml.so

Next, create a symlink of yaml.ini file:

sudo ln -s /etc/php/7.0/mods-available/yaml.ini /etc/php/7.0/fpm/conf.d/20-yaml.ini
sudo ln -s /etc/php/7.0/mods-available/yaml.ini /etc/php/7.0/cli/conf.d/20-yaml.ini

Finally restart php-fpm service for these changes to take effect:

sudo service php7.0-fpm restart

Installing Composer

Composer is a dependency manager for PHP. It will pull in all the required libraries and dependencies you need for your project.

You can install it with the following command:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Next, you will need to create a new PHP-FPM pool for your user like www-data:

You can do this by creating www-data.conf file:

sudo nano /etc/php/7.0/fpm/pool.d/www-data.conf

Add the following lines:

[www-data]
user = www-data
group = www-data
listen = /var/run/php-fpm-www-data.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Save and close the file, restart PHP-FPM service:

sudo service php7.0-fpm restart

Installing Grav CMS

You can install Grav by using the git command:

First, change the directory to your default document root directory:

cd /var/www/html/

sudo git clone https://github.com/getgrav/grav.git

Next, change the directory to grav and install all dependencies:

cd grav
sudo composer install --no-dev -o

Finally install the grav with the following command:

sudo ./bin/grav install

Install and Configure Nginx

Once grav is installed, you can install Nginx with the following command:

sudo apt-get install nginx

Next, you will need to create a new Nginx server block.

You can do this by creating gravcms.conf inside /etc/nginx/sites-available/ directory:

sudo nano /etc/nginx/sites-available/gravcms.conf

Add the following lines:

    server {

    listen      80;
    server_name gravcms;
    root /var/www/html/grav/;
    index index.php;

    access_log  /var/log/nginx/gravcms.access.log;
    error_log   /var/log/nginx/gravcms.error.log;

    location / {
      try_files $uri $uri/ /index.php$args;
    }

    location ~* /(.git|cache|bin|logs|backups)/.*$ { 
        return 403; 
    }

    location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat)$ { 
        return 403; 
    }

    location ~* /user/.*\.(txt|md|yaml|php|pl|py|cgi|twig|sh|bat)$ { 
        return 403; 
    }

    location ~ /(LICENSE|composer.lock|composer.json|nginx.conf|web.config|htaccess.txt|\.htaccess) { 
        return 403; 
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm-www-data.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
}

Next, activate the server block by creating a symlink:

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

Next, test the Nginx for configuration syntax errors and restart Nginx service:

sudo nginx -t
sudo /etc/init.d/nginx restart

Once Nginx is installed and configured, you can proceed with installing Grav Admin Plugin.

##cInstalling and Configuring Grav Admin Plugin

To install Grav admin plugin, first change the directory to /var/www/html/grav:

cd /var/www/html/grav

Next, install the admin plugin by running the following command:

sudo ./bin/gpm install admin

The above command will install the admin plugin plus its dependency plugins.

You will also need to set the proper permissions for the grav directory. You can do this by running the following command:

sudo chown -R www-data:www-data /var/www/html/grav
sudo chmod -R 755 /var/www/html/grav

Once the admin plugin is installed, it’s time to access Grav dashboard.

Open your web browser and type the URL http://your-ip-address, you will be prompted to create a new admin user as shown below:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/88181792.png” alt=”” />

Fill in all the details such as your username, email address, password, full name, title and then click on Create User button. You should see the following page:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/2106394863.png” alt=”” />

If you want to update the Grav admin plugin, you can click the Update button to update plugins and themes from the Grav dashboard.

You can also update the admin plugin through your terminal using the following command:

cd /var/www/html/grav
sudo ./bin/gpm selfupgrade -f

The above command will upgrade the Grav to the latest version.

You can also update all your plugins and themes to the latest version with the following command:

sudo ./bin/gpm update -f

Congratulations! you have successfully installed Grav CMS on your server.

I hope you can now easily deploy the Grav CMS on your system.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]