This guide installs a minimal Grav stack with Apache and PHP, then deploys Grav files.
It supports Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Grav
hosts: grav
become: true
vars:
grav_version: "1.7.49"
grav_webroot: /var/www/grav
tasks:
- name: Install dependencies on Debian/Ubuntu
apt:
name:
- apache2
- php
- php-xml
- php-mbstring
- php-curl
- php-gd
- php-zip
- php-intl
- php-ctype
- php-dom
- php-simplexml
- php-openssl
- unzip
- wget
- curl
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
dnf:
name:
- httpd
- php
- php-xml
- php-mbstring
- php-curl
- php-gd
- php-zip
- php-intl
- unzip
- wget
state: present
when: ansible_os_family == "RedHat"
- name: Ensure web service is enabled and started
service:
name: "{{ 'apache2' if ansible_os_family == 'Debian' else 'httpd' }}"
state: started
enabled: true
- name: Create Grav web root
file:
path: "{{ grav_webroot }}"
state: directory
mode: "0755"
- name: Download Grav archive
get_url:
url: "https://github.com/getgrav/grav/releases/download/{{ grav_version }}/grav-admin-v{{ grav_version }}.zip"
dest: /tmp/grav.zip
mode: "0644"
- name: Extract Grav
unarchive:
src: /tmp/grav.zip
dest: /tmp
remote_src: true
- name: Sync Grav files to web root
shell: |
set -euo pipefail
src_dir="$(find /tmp -maxdepth 2 -type d -name 'grav-admin' | head -n1)"
rsync -a --delete "$src_dir"/ "{{ grav_webroot }}/"
args:
executable: /bin/bash
- name: Set ownership for web root
file:
path: "{{ grav_webroot }}"
state: directory
recurse: true
owner: "{{ 'www-data' if ansible_os_family == 'Debian' else 'apache' }}"
group: "{{ 'www-data' if ansible_os_family == 'Debian' else 'apache' }}"
- name: Set directory permissions
find:
paths: "{{ grav_webroot }}"
type: directory
mode: "0755"
- name: Set file permissions
find:
paths: "{{ grav_webroot }}"
type: file
mode: "0644"
user/ and backup/ directories.Beyond this playbook, we offer:
Contact our automation team: office@linux-server-admin.com