Grav on PHP 7 on Ubuntu on Azure

December 4, 2016

Grav 1.1.8

Grav is a modern open source flat-file CMS for PHP 7. Grav is a Fast, Simple, and Flexible file-based Web-platform. While Grav follows principles similar to other flat-file CMS platforms, it has a different design philosophy than most. Learn more about Grav flat-file CMS.

Ubuntu 16.04 LTS

Ubuntu Server is the world's most popular Linux for cloud environments. Updates and patches for Ubuntu 16.04 will be available until April 2021. Find out more information about Ubuntu on Azure.

Microsoft Azure: Cloud

Login to your Microsoft Azure Portal, and search the marketplace for the official Ubuntu Server 16.04 LTS image from Canonical to create a new Linux Vitual Machine, using the resource manager.

Select SSH Key-Based Authentication during config process to create the new vm with additional security defaults, and disable the ability to login with a password.

A typical Azure VM starter example.

DS1_V2 Standard

  • Australia East datacenter
  • Ubuntu 16.04 LTS (Canonical)
  • 1 Core
  • 3.5GB
  • 2 Data Disks
  • 3200 Max IOPS
  • 7GB Local SSD
  • Load balancing
  • Premium disk support
  • SSH Key-Based Authentication

$93.31 NZD/MONTH (estimated pricing)


Preparing Ubuntu on Azure for Grav on PHP 7

Packages required in addition to the Ubuntu on Azure base image

  • apache2
  • build-essential
  • libapache2-mod-php
  • libnet-libidn-perl
  • libyaml-dev
  • php7.0
  • php7.0-curl
  • php7.0-gd
  • php7.0-mbstring
  • php7.0-mcrypt
  • php7.0-xml
  • php7.0-zip
  • php-apcu
  • php-all-dev
  • php-cgi
  • php-curl
  • php-dev
  • php-gd
  • php-gmp
  • php-pear
  • php-xdebug
  • ufw

System Update

$ sudo apt-get update && sudo apt-get upgrade
$ sudo reboot now

Package Install

$ sudo apt-get install apache2 build-essential php7.0 php7.0-curl php7.0-gd php7.0-zip php7.0-mbstring php7.0-mcrypt php7.0-xml php-apcu php-pear libyaml-dev php-xdebug ufw libapache2-mod-php libnet-libidn-perl php-all-dev php-cgi php-curl php-dev php-gd php-gmp

Apache Config

Edit the default apache2.conf

$ sudo nano /etc/apache2/apache2.conf

    ServerName {{your_hostname}}

Test Apache Config

$ sudo apache2ctl configtest

Restart Apache

$ sudo systemctl restart apache2

Firewall Settings

Allow incoming webserver traffic

$ sudo ufw allow in "Apache Full"

Allow SSH (!important, configure SSH only access)

$ sudo ufw allow ssh

Enable Firewall

$ sudo ufw enable

Checking Firewall Status

$ sudo ufw status

Apache mod_dir

Edit dir.conf to order index.php to process before index.html

$ sudo nano /etc/apache2/mods-enabled/dir.conf

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
    </IfModule>

Restart Apache

$ sudo systemctl restart apache2

Installing Grav + Grav Admin plugin

Fetch latest Grav Core + Admin Plugin release from GitHub, and extract into your webserver directory (/var/www).

$ cd ~/ 
$ wget https://github.com/getgrav/grav/releases/download/1.1.8/grav-admin-v1.1.8.zip
$ sudo unzip grav-admin-v1.1.8.zip -d "/var/www/"

File and Folder permissions

For Grav to function properly. When using either the CLI or GPM, the user running PHP from the command line, also needs to have the appropriate permissions to modify files. By default, Grav will install with 644 and 755 permissions for files and folders respectively.

$ cd /var/www/grav-admin
$ sudo chmod -R 755 .
$ sudo chgrp -R www-data .
$ find . -type f | xargs chmod 664
$ find . -type d | xargs chmod 775
$ find . -type d | xargs chmod +s
$ umask 0002

Apache Virtual Host Config

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/grav-admin.conf
$ sudo nano /etc/apache2/sites-available/grav-admin.conf

<VirtualHost *:80>
    <Directory /var/www/grav-admin>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ServerAdmin {{email_address}}
    ServerName {{your_domain.com}}
    ServerAlias {{www.your_domain.com}}

    DocumentRoot /var/www/grav-admin

[ --more-- ]

For development, set ServerName to localhost, and comment out ServerAlias

Enable Apache mod_rewrite

$ sudo a2enmod rewrite

Enable Grav site

$ sudo a2ensite grav-admin.conf

Disable default site

sudo a2dissite 000-default.conf

Finish setting up Grav Admin

To setup the default administrator account and password for Grav Admin, and complete this install, visit the new site from your browser.

http://{{SERVER}}/admin

Next steps

Learn Grav https://learn.getgrav.org/

Grav Skeletons https://getgrav.org/downloads/skeletons

Grav Themes https://getgrav.org/downloads/themes

Grav Skeletons https://getgrav.org/downloads/plugins


Date : December 4, 2016
Author : Joseph Patton-Robson
Tags : php, grav, azure, ubuntu, cms, apache

NEXT