This guide installs a Drupal base stack with Apache, PHP, MariaDB, and Composer.
It supports Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Drupal
hosts: drupal
become: true
vars:
drupal_webroot: /var/www/drupal
drupal_project: /var/www/drupal_project
tasks:
- name: Install dependencies on Debian/Ubuntu
apt:
name:
- apache2
- mariadb-server
- php
- php-mysql
- php-gd
- php-xml
- php-mbstring
- php-curl
- php-zip
- php-intl
- composer
- unzip
- curl
- git
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
dnf:
name:
- httpd
- mariadb-server
- php
- php-mysqlnd
- php-gd
- php-xml
- php-mbstring
- php-curl
- php-zip
- php-intl
- composer
- unzip
- git
state: present
when: ansible_os_family == "RedHat"
- name: Ensure web and database services are enabled and started
service:
name: "{{ item }}"
state: started
enabled: true
loop:
- "{{ 'apache2' if ansible_os_family == 'Debian' else 'httpd' }}"
- mariadb
- name: Create Drupal project directory
file:
path: "{{ drupal_project }}"
state: directory
mode: "0755"
- name: Create Drupal recommended project using Composer
command: composer create-project drupal/recommended-project {{ drupal_project }}
args:
creates: "{{ drupal_project }}/composer.json"
- name: Create web root symlink
file:
src: "{{ drupal_project }}/web"
dest: "{{ drupal_webroot }}"
state: link
drush site:install) for production.We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact