This guide installs a minimal WordPress stack with Apache, PHP, and MariaDB.
It supports Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install WordPress
hosts: wordpress
become: true
vars:
wordpress_webroot: /var/www/wordpress
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
- unzip
- wget
- 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
- unzip
- wget
- curl
- 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 WordPress web root
file:
path: "{{ wordpress_webroot }}"
state: directory
mode: "0755"
- name: Download WordPress
get_url:
url: https://wordpress.org/latest.tar.gz
dest: /tmp/wordpress.tar.gz
mode: "0644"
- name: Extract WordPress archive
unarchive:
src: /tmp/wordpress.tar.gz
dest: /tmp
remote_src: true
- name: Deploy WordPress files
command: rsync -a --delete /tmp/wordpress/ {{ wordpress_webroot }}/
- name: Set ownership for web root
file:
path: "{{ wordpress_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' }}"
wp-config.php, vhost, and TLS before production.We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact