• Get In Touch
January 12, 2017

How to Install Grav CMS on CentOS 7

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

Grav is a free and open source content management system. Unlike other CMS, Grav does not use a database to store its data. Instead, the data is stored in flat files in markdown format. Grav is written in PHP, and it is known for its very fast performance. Grav is very popular CMS used by numerous beautiful websites around the globe.

Requirements

Grav does not require any special hardware requirements. It can be installed on servers with a small amount of RAM. All the necessary dependencies will be installed throughout the tutorial. You will need a minimal installation of CentOS 7 with root access on it. If you are logged in as a non-root user, you can run sudo -i to switch to root user.

Installing Grav CMS

Before installing any package, it is recommended you update the server and available packages. Run the following command to do so.

yum -y update

Now you will need to install Apache web server and PHP version greater than 5.5.9. To install Apache, run the following command.

yum -y install httpd

Since Grav uses a PHP version greater than 5.5.9 but the YUM repository contains PHP version 5.4 only. Hence we will need to use the Webtatic repository to install a version of PHP greater than 5.5.9. Run the following commands for installing EPEL repository as EPEL repository is required before we install Webtatic repository.

yum -y install epel-release
yum -y update

Now install Webtatic repository using the following commands.

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y update
yum clean all

To install PHP 5.6 and all the required PHP modules, run the following command.

yum -y install php56w php56w-curl php56w-openssl php56w-zip php56w-apcu php56w-gd php56w-mysql php56w-xml php56w-mbstring php56w-opcache

To install PHP 7.0 and all the required PHP modules, run the following command.

yum -y install php70w php70w-curl php70w-openssl php70w-zip php70w-pecl-apcu php70w-gd php70w-mysql php70w-xml php70w-mbstring php70w-opcache

Make sure that you are using only one of the PHP versions mentioned above. Once you have PHP installed, you can check the version of PHP using the following command.

php -v

For example, for PHP 7.0, you will likely see the following output:

[root@ip-172-31-6-206 ~]# php -v
PHP 7.0.14 (cli) (built: Dec 10 2016 11:35:27) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.14, Copyright (c) 1999-2016, by Zend Technologies

Make sure that your PHP version is not older than 5.5.9. Now start Apache web server and enable it to start at boot time using the following commands:

systemctl start httpd
systemctl enable httpd

Now you will need to Enable Mod_rewrite by editing /etc/httpd/conf/httpd.conf using your favorite text editor.

nano /etc/httpd/conf/httpd.conf

If you do not have nano installed, you can run yum -y install nano to install nano editor. Find the following line under <Directory "/var/www/html"> block.

AllowOverride None

Change it to AllowOverride All.

Now restart your web server using the following command.

systemctl restart httpd

There are many ways to download Grav CMS. You can download the archive from Grav website, or you can use composer to install the package, or you can download the repository from Github.

Grav provides many types of pre-built zip archive. You can choose to download the Grav core package only. You can also decide to download the core package with admin plugin. Admin plugin provides the functionality of administering Grav through the web browser. You can also download the skeleton packages, which is an all in one package consisting of Grav core module and the themes, plugin and sample pages. At the time of writing this tutorial, the latest version of Grav is 1.1.12. You can check for the updated links at Grav Downloads page. Make sure that you only download and extract any one of these three types of packages. You can use all in one skeleton packages to get started quickly as Grav provides many different skeleton packages.

To download the Grav core package only run the following command.

cd /opt
wget https://github.com/getgrav/grav/releases/download/1.1.12/grav-v1.1.12.zip

Now extract the files using the following command.

unzip grav*.zip

If you don’t have unzip installed, run yum -y install unzip. The above command will extract Grav in grav directory, to move all the files including .htaccess to the web root directory, run the following command.

mv /opt/grav/{.[!.],}* /var/www/html

To download the Grav package with admin plugin, run the following command.

wget https://github.com/getgrav/grav/releases/download/1.1.12/grav-admin-v1.1.12.zip

Now extract the files using the following command.

unzip grav*.zip

The above command will extract Grav in grav-admin directory, to move all the files including .htaccess to the web root directory, run the following command.

mv /opt/grav-admin/{.[!.],}* /var/www/html

To download any skeleton or all in one package, you will need to go to Scalatons downloads page. Select any package you wish to download and download the package using wget command. For example, the command below will download Grav Skeleton Course Hub Site.

cd /opt
wget https://github.com/hibbitts-design/grav-skeleton-course-hub/releases/download/v1.4.1/grav-skeleton-course-hub-site.zip

Now extract the files using the following command.

unzip grav-skeleton-course-hub-site.zip

The above command will extract Grav in grav-skeleton-course-hub-site directory, to move all the files including .htaccess to the web root directory, run the following command.

mv /opt/grav-skeleton-course-hub-site/{.[!.],}* /var/www/html

Once you have downloaded and moved any one of the above packages, you need to configure SELinux settings. To temporary disable SELinux, run the following command.

setenforce 0

To completely disable the SELinux you will need to edit /etc/selinux/config file.

nano /etc/selinux/config

If you don’t have nano installed, you can install it using yum -y install nano Find the following line:

SELINUX=enforcing

Change it to:

SELINUX=disabled

Now you will need to reboot your server so that the new configuration can take effect. Once the server is rebooted, you will need to provide the ownership of the application to web server user using the following command.

chown -R apache:apache /var/www/html

You can now browse the following URL using your favorite web browser.

http://yourServerIP/

or

http://yourdomain.com/

If you have downloaded only the Grav core package, you will see the following instruction page.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/571817800.png” alt=”” />

If you have downloaded Grav with Admin plugin or Grav Skeleton package, then you will see the following interface to create an admin user.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/2059102565.png” alt=”” />

Provide the required information like username, email, password, name and title. Click Create User button, and it will create the administrator user, and you will be automatically logged into to your admin dashboard.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/2104473620.png” alt=”” />

Managing the Grav Installation

Grav provides a command line tool to manage the Grav installation. You can use this tool to install themes or plugins or to upgrade the installation. You will need to run the command in the root of the Grav installation, in our case, it is /var/www/html.
Navigate to the above directory using the following command.

cd /var/www/html

To see a list of available themes and plugins, run the following command.

bin/gpm index

You will see output similar to this.

[root@ip-172-31-6-206 html]# bin/gpm index

GPM Releases Configuration: Stable

PLUGINS [ 157 ]
-------------------------------------------------------------------------------------
| Count | Name                     | Slug                 | Version | Installed     |
=====================================================================================
| 1     | Twig Cache               | twigcache            | v1.2.0  | not installed |
| 2     | Staticfilecache          | staticfilecache      | v1.0.0  | not installed |
| 3     | Srcset Fallback          | srcset-fallback      | v1.0.0  | not installed |
| 4     | Embed                    | embed                | v1.0.0  | not installed |
| 5     | Cachebuster              | cachebuster          | v1.0.0  | not installed |

.....

To get more information about the theme or plugin, run the following command.

bin/gpm info <name_of_plugin/theme>

For example, the following command will provide the information about Deliver theme.

bin/gpm info deliver

The output of the command will be similar to shown below.

[root@ip-172-31-6-206 html]# bin/gpm info deliver

GPM Releases Configuration: Stable

Found package 'deliver' under the 'Themes' section

Deliver [deliver]
-----------------
Deliver theme is a port of the Michael Reimer's Deliver Free PSD theme.

Author      : Team Grav <devs@getgrav.org> <http://getgrav.org>
Version     : 1.6.2
Keywords    : deliver, theme, modern, fast, responsive, html5, css3
Last Update : Tue, 16 Sep 2014, 00:07:16, +00:00
Homepage    : https://github.com/getgrav/grav-theme-deliver
Demo        : http://demo.getgrav.org/deliver-skeleton/
Repository  : https://github.com/getgrav/grav-theme-deliver
Bugs        : https://github.com/getgrav/grav-theme-deliver/issues
Download    : https://github.com/getgrav/grav-theme-deliver/zipball/1.6.2
License     : MIT

To install a plugin or theme, run the following command.

bin/gpm install <name_of_plugin/theme>

For example the command below will install Deliver theme.

bin/gpm install deliver

To update the Grav core package, run the following command.

bin/gpm selfupgrade -f

To update Grav core along with all the other plugins and themes, run the following command.

bin/gpm update -f

Adding Content

Grav stores its pages in /home/pages directory. If you navigate to the directory, you will see directories with numbers. Each directory represents a page in Grav site, the content of the page is stored in default.md file. The numbers in the name of the directory tells the order of the page, for example, 01 will always be ahead of 02. If you have just installed Grav core, there will be only one directory, 01.home. The text portion of the name of directory tells the URL of the page.

To create a new page you will need to create a new directory. Run the following command to do so.

cd /var/www/html/user/pages
mkdir 02.newpage

Now create the default.md file using the following command.

nano 02.newpage/default.md

The pages in Grav CMS are created in Markdown format. Add the following sample text into the file.

---
title: New Page
menu: New Page
---
# Hi There, It's a New Page!

This is sample content, you can **easily** add the content using *Markdown* format.

## It's just a sub heading.

Save the file and exit from the editor. The content between the dashed line --- are page headers written in a very simple format called YAML. It provides page headers in Markdown files.

You can now refresh your web page to see a new menu item, navigate to the page after clicking on the menu item.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/1394364861.png” alt=”” />

Conclusion

In this tutorial, we have learned how to install Grav CMS in CentOS 7. We also learned how to use the command line tool gpm to manage the Grav installation. We also added a new page to our Grav website.

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 […]