Learn How To Setup Grav CMS On Ubuntu 14

October 29, 2019

Table of Contents

    Introduction

    Grav is a modern flat file CMS that is fast, extensible and open-source. It’s easy to use and has a host of impressive plugins, one of which is an admin for it.

    Installation

    Spin up a Ubuntu 14 IT Web Services instance and run below commands to install some essential utilities, PHP 7, and Nginx. Note: You can put this portion in a startup script and spin up your using it to make the process faster.

    export DEBIAN_FRONTEND=noninteractive
    sudo apt-get update -y
    sudo apt-get upgrade -y
    # install some essential tools
    sudo apt-get install -y acl curl git software-properties-common unzip zip
    # install php7
    sudo apt-add-repository ppa:ondrej/php -y
    sudo apt-get update -y
    sudo apt-get install -y --force-yes php7.0-cli php-curl php-gd php7.0-zip php7.0-mcrypt php-apcu php-xml php-mbstring php-intl
    # install nginx
    sudo apt-get install -y --force-yes nginx
    sudo apt-get install -y --force-yes php7.0-fpm
    # tweak php ini file
    sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/cli/php.ini
    sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
    # remove default site setup and restart nginx
    rm -f /etc/nginx/sites-enabled/*
    rm -f /etc/nginx/sites-available/*
    service nginx restart
    

    Configure Server for Grav

    SSH into your server as root from your terminal.

    ssh root@[itweb.services-instance-ip]
    

    https://www.itweb.services/tutorials/linux-guides/securing-ssh-on-ubuntu-14-04 on a public facing site

    Create a directory to hold grav site

    # create directory
    mkdir -p /sites/grav && cd /sites/grav
    # set permissions
    chmod -R 775 /sites
    chown -R www-data:www-data /sites
    chmod -R g+s /sites
    # put temporary index file
    echo "<h3>Welcome Home...</h3>" >> index.php
    echo "<?php phpinfo();" >> index.php
    

    Setup a nginx host to for the site:

    1. cd into nginx sites available directory cd /etc/nginx/sites-available/
    2. Create a config file for grav site sudo nano grav
    3. Paste below content into file, then save and exit (Ctrl+X -> Y -> hit Enter)

      server {
          listen 80;
          server_name itweb.services.dev; #NOTE: itweb.services.dev should be replaced with your domain name eventually
          root /sites/grav;
          index index.html index.htm index.php;
          charset utf-8;
          location / {
              try_files $uri $uri/ /index.php$is_args$args;
          }
          location ~ .php$ {
              fastcgi_split_path_info ^(.+.php)(/.+)$;
              fastcgi_pass unix:/run/php/php7.0-fpm.sock;
              fastcgi_index index.php;
              include fastcgi_params;
          }
      }
      
    4. Enable grav config

      sudo ln -s /etc/nginx/sites-available/grav /etc/nginx/sites-enabled/grav
      
    5. Restart nginx and php-fpm

      sudo service nginx restart
      sudo service php7.0-fpm restart
      
    6. Update servers host file sudo bash -c "echo '127.0.0.1 itweb.services.dev' >> /etc/hosts" _(Note: itweb.services.dev should be replaced with your domain name eventually)

    7. You should be able to browse to http://[itweb.services-instance-ip] and see a “Welcome Home” message along with some info on the version of PHP installed (if you don’t see this or are using itweb.services.dev as used above, you’ll have to perform additional step below to add a host entry for itweb.services.dev on your local machine)

    Update your local machine’s host file (Optional)

    Add below entry to your host file.

    [itweb.services-instace-ip]     itweb.services.dev
    

    Your host file should be located in one of the listed areas below depending on what OS you are running.

    • Windows – c:windowssystem32driversetchosts
    • Linux – /etc/hosts
    • Mac – /private/etc/hosts

    Install Grav

    1. Install composer and create a grav project.

      # install composer
      sudo curl -sS https://getcomposer.org/installer | php
      sudo mv composer.phar /usr/local/bin/composer
      # create grav project
      cd /sites
      mv grav grav-test
      composer create-project getgrav/grav
      # below is only needed if you logged as sudo
      
      Learn Securing SSH on Ubuntu 14.04
      chown -R www-data:www-data /sites
    2. Browse to http://itweb.services.dev (or your domain) and you should be greeted with a welcome page that says “Grav is Running!”.

    Need help?

    Do you need help setting up this on your own service?
    Please contact us and we’ll provide you the best possible quote!