How to Install Grav CMS with Nginx on Debian 9

screenshot 2019 05 30 at 02

How to Install Grav CMS with Nginx on Debian 9

Grav is a FastSimple, and Flexible, file-based Web-platform. It follows similar principles to other flat-file CMS platforms but has a different design philosophy than most. Grav comes with a powerful Package Management System to allow for simple installation and upgrading of plugins and themes, as well as simple updating of Grav itself. 

The underlying architecture of Grav is designed to use well-established and best-in-class technologies to ensure that Grav is simple to use and easy to extend. Some of these key technologies include:

  • Twig Templating: for powerful control of the user interface
  • Markdown: for easy content creation
  • YAML: for simple configuration
  • Parsedown: for fast Markdown and Markdown Extra support
  • Doctrine Cache: layer for performance
  • Pimple Dependency Injection Container: for extensibility and maintainability
  • Symfony Event Dispatcher: for plugin event handling
  • Symfony Console: for CLI interface
  • Gregwar Image Library: for dynamic image manipulation

In this guide, we will guide you step-by-step through the Grav CMS installation process on the Debian 9 operating system using Nginx as the web server, and acme.sh and Let’s Encrypt for HTTPS.


  • Web Server (Apache, Nginx, LiteSpeed, Lightly or IIS). In this guide, we will use NGINX.
  • PHP 7.1.3 or higher with the following PHP extensions: curl, ctype, dom, gd, json, mbstring, openssl, session, simplexml, xml, zip, apcu(optional), opcache(optional).


  • An operating system running Debian 9.
  • A non-root user with sudo privileges.

Initial steps

Check your Debian version:
lsb_release -ds
# Debian GNU/Linux 9.9 (stretch)

Set up the timezone:
sudo dpkg-reconfigure tzdata

Update your operating system packages (software). This is an important first step because it ensures you have the latest updates and security fixes for your operating system’s default software packages:
sudo apt update && sudo apt upgrade -y

Install some essential packages that are necessary for basic administration of the Debian operating system:
sudo apt install -y curl wget vim git unzip socat apt-transport-https

Step 1 – Install PHP and PHP extensions

Grav CMS requires PHP version 7.1 or greater. Debian has PHP version 7 in the default repository, thus you will need to use third-party repo to install a newer version.
sudo apt install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Install PHP 7.2, as well as the necessary PHP extensions:
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

Check the PHP version:
php --version

# PHP 7.2.18-1+0~20190503103213.21+stretch~1.gbp101320 (cli) (built: May  3 2019 10:32:13) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.18-1+0~20190503103213.21+stretch~1.gbp101320, Copyright (c) 1999-2018, by Zend Technologies

PHP-FPM service is automatically started and enabled on reboot on Debian 9 system, so there is no need to start and enable it manually. We can move on to the next step, which is SSL setup.

Step 2 – Install Acme.sh client and obtain Let’s Encrypt certificate (optional)

Securing your website with HTTPS is not necessary, but it is a good practice to secure your site traffic. In order to obtain TLS certificate from Let’s Encrypt we will use Acme.sh client. Acme.sh is a pure Unix shell software for obtaining TLS certificates from Let’s Encrypt with zero dependencies. 

Download and install Acme.sh:
sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail [email protected]
cd ~

Check Acme.sh version:
/etc/letsencrypt/acme.sh --version
# v2.8.0

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength 2048
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength ec-256

After running the above commands, your certificates and keys will be in:

  • For RSA: /etc/letsencrypt/example.com directory.
  • For ECC/ECDSA: /etc/letsencrypt/example.com_ecc directory.

Step 3 – Install and configure NGINX

Install the NGINX web server:
sudo apt install -y nginx

Check the NGINX version:
nginx -v
# nginx version: nginx/1.10.3

Run sudo vim /etc/nginx/sites-available/grav.conf and populate the file with the following configuration:
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

Check NGINX configuration for syntax errors:

sudo nginx -t

Reload NGINX service:
sudo systemctl reload nginx.service

Step 4 – Install Grav CMS

Create a document root directory where Grav should reside in:
sudo mkdir -p /var/www/grav

Change the ownership of the /var/www/grav directory to {your_user}. Replace {your_user} in the command below with the username that you are currently logged into Debian.:
sudo chown -R {your_user}:{your_user} /var/www/grav

Navigate to the document root directory:
cd /var/www/grav

Download the latest version from the official page and extract the zip file:
wget https://getgrav.org/download/core/grav-admin/1.6.9
unzip 1.6.9
mv grav-admin/* . && mv grav-admin/.* .
rm -rf grav-admin 1.6.9

NOTE: Update download URL if there is a newer release.

Change ownership of the /var/www/grav directory to www-data:
sudo chown -R www-data:www-data /var/www/grav

Step 5 – Complete the Grav setup

Open your site in a web browser and you should see a page that asks you to create a Grav admin account. Create one and proceed by clicking the “Create User” button:


That’s it. Your Grav installation is complete.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !