Post

Grav Install - Ubuntu 22.04

Grav is a free software, self-hosted content management system (CMS) written in the PHP programming language and based on the Symfony web application framework. It uses a flat file database for both backend and frontend. Grav is designed to have a shallow learning curve, and to be easy to set up.

Update Ubuntu

1
sudo apt update && sudo apt upgrade -y

Install Nginx and PHP

1
sudo apt-get install nginx php php-cli php-fpm php-common php-curl php-gd php-json php-mbstring php-xml php-zip php-opcache php-apcu unzip -y

Edit PHP

1
sudo nano /etc/php/8.1/fpm/php.ini

Required changes:

1
2
3
4
5
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = Your_Timezone (make sure you uncomment this line, remove the ; in front of the line)

Restart PHP

1
sudo systemctl restart php8.1-fpm

Install Grav CMS

1
cd /var/www/html

Check Grav Webstie for the latest release

1
sudo wget https://getgrav.org/download/core/grav-admin/1.7.42.3

Unzip Grav:

1
sudo unzip 1.7.42.3

Rename file folder to grav:

1
sudo mv grav-admin grav

Set permissions on files:

1
sudo chown -R www-data:www-data /var/www/html/grav

Nginx Config File

Create the Grav Nginx config file:

1
sudo nano /etc/nginx/conf.d/grav.conf

Cut and past the following into the file, edit ‘server_name’ to the hostname of your server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
server {

listen 80;

server_name grav.example.com;
root /var/www/html/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/php8.1-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
 }

}

Test the config file:

1
sudo nginx -t

Should return the following:

1
2
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx:

1
sudo systemctl restart nginx

Check the status of Nginx:

1
sudo systemctl status nginx

Should return the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-09-06 20:15:08 UTC; 25s ago
       Docs: man:nginx(8)
    Process: 14001 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 14002 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 14003 (nginx)
      Tasks: 3 (limit: 76963)
     Memory: 3.4M
        CPU: 26ms
     CGroup: /system.slice/nginx.service
             |-14003 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             |-14004 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
             `-14005 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">

Sep 06 20:15:08 Grav systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 06 20:15:08 Grav systemd[1]: Started A high performance web server and a reverse proxy server.

Grav Configuration Issue

If you find issues with the scheduler in Grav, run the following command:

1
sudo crontab -u www-data -e

And add this line to the bottom of the file:

1
* * * * * cd /var/www/html/grav;/usr/bin/php bin/grav scheduler 1>> /dev/null 2>&1

Ctrl X to exit.

Accessing The Grav Webpage

Once all the above is completed, you should be able to access the site in your browser.

http://your_server_ip

This post is licensed under CC BY 4.0 by the author.