This guide installs a minimal Craft CMS stack with Nginx, PHP-FPM, MariaDB, and Composer.
It supports Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Craft CMS
hosts: craftcms
become: true
vars:
craft_root: /var/www/craftcms
craft_user: www-data
tasks:
- name: Install dependencies on Debian/Ubuntu
apt:
name:
- nginx
- mariadb-server
- php-fpm
- php-mysql
- php-mbstring
- php-xml
- php-curl
- php-zip
- php-intl
- php-bcmath
- composer
- unzip
- curl
- git
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
dnf:
name:
- nginx
- mariadb-server
- php
- php-fpm
- php-mysqlnd
- php-mbstring
- php-xml
- php-curl
- php-zip
- php-intl
- php-bcmath
- composer
- unzip
- git
state: present
when: ansible_os_family == "RedHat"
- name: Ensure required services are enabled and started
service:
name: "{{ item }}"
state: started
enabled: true
loop:
- nginx
- mariadb
- name: Create Craft CMS directory
file:
path: "{{ craft_root }}"
state: directory
mode: "0755"
owner: "{{ craft_user if ansible_os_family == 'Debian' else 'nginx' }}"
group: "{{ craft_user if ansible_os_family == 'Debian' else 'nginx' }}"
- name: Install Craft CMS project with Composer
command: composer create-project craftcms/craft {{ craft_root }}
args:
creates: "{{ craft_root }}/composer.json"
.env, database provisioning, queue worker, and TLS reverse proxy before production use.We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact