Self-Hosting Wordpress using Docker on Ubuntu 24.04 with Nginx and SSL

One click setup using a script that utilized docker compose.
November 16, 2025 by
Self-Hosting Wordpress using Docker on Ubuntu 24.04 with Nginx and SSL
Alixsander Haj Saw
| No comments yet

Introduction

We'll be installing Wordpress on an Ubuntu 24.04 server using a setup script that utilized docker compose to create the necessary containers, volumes, and configurations.

4 containers are created in this setup, Wordpress for the application, mysql for the database, nginx as the web server, and certbot for generating free let's encrypt certificates.

Pre-requisites

  • Ubuntu server
  • Domain pointing to the server
  • Docker and docker compose installed
  • Ports 80 and 443 open
  • Root or sudo access

Install docker on Ubuntu using apt by following their official documentation here:

https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

Check if UFW us enabled using ufw status if it is, make sure both http and https are allowed:

sudo ufw allow http
sudo ufw allow https

You can find the video version of this article below:

https://youtu.be/GaHmcL92aOs


Project setup

The setup can be cloned from the following repository:

git clone https://github.com/opensourcehustle/wordpress-full-docker-setup.git

This repository has the following structure:

.
├── docker-compose.yml
├── .env.example
├── setup.sh
├── renewal.sh
├── themes/              # Custom WordPress themes
├── plugins/             # Custom WordPress plugins
└── nginx/
    └── conf.d/
        ├── wordpress-http.conf
        └── wordpress-https.conf.template

docker-compose.yml contains our 4 containers and their volumes setup.

.env.example contains environment variables that we'll updated.

setup.sh contains the full setup script for Wordpress, which includes loading the environment variables, configuring the initial nginx configuration using the provided domain over http, generating let's encrypt ssl certificate, and finally updating the nginx configuration file to serve traffic securely over https.

Both theme and plugins directories are volumes shared with the Wordpress container, which will enable us to add custom themes/plugins to our Wordpress site by adding them to these directories.

nginx directory contains all the necessary nginx configurations, with the initial http configuration for generating certificates and https as the final configuration. This is a volume that is shared with the nginx container.

renewal.sh script contains the renewal script for generating new certificates, it will be used within a cronjob to request certificate renewal.


Running the installation script

Before running the script, we'll need to configure our environment variables, start with creating the .env file:

cp .env.example .env

Now edit the .env file:

nano .env

Edit the following values:

  • MYSQL_ROOT_PASSWORD: Strong root password for MySQL
  • MYSQL_DATABASE: Database name (default: wordpress_db)
  • MYSQL_USER: Database user (default: wordpress_user)
  • MYSQL_PASSWORD: Strong password for database user
  • DOMAIN: Your domain name (e.g., example.com)
  • SSL_EMAIL: Your email for Let's Encrypt notifications

To run the installation script, we must first make the script executable by running:

chmod +x setup.sh

Then run the script using:

sudo ./setup.sh

The script will:

  1. Create necessary Docker volumes
  2. Start MySQL, WordPress, and Nginx
  3. Request SSL certificates from Let's Encrypt
  4. Configure HTTPS

Now you should be able to complete the Wordpress installation wizard by visiting your domain name.


Certificate renewals

To setup automatic certificate renewals, first make the renewal script executable:

chmod +x renewal.sh

Next access the crontab:

sudo crontab -e

and add the following line at the bottom, make sure you replace the path with the actual path to your renewal.sh location:

0 0,12 * * * /path/to/your/wordpress/renewal.sh >> /var/log/certbot-renewal.log 2>&1

This crontab will run twice daily, attempting to renew the certificate, if the certificate renews successfully then it will also reload nginx.


Additional notes

Add custom themes/plugins to the themes/plugins directories which are shared with the Wordpress container. You can additionally create deployment pipelines to automatically push updates to these directories using github actions.

Visit the repository used in this article for additional details/setups:

https://github.com/opensourcehustle/wordpress-full-docker-setup/tree/main


Sign in to leave a comment