Support Online
Skip to main content

Installing WordPress with Docker Compose: Step-by-Step Guide

What Will You Learn in This Guide?

In this guide, you will learn how to stand up the WordPress infrastructure with a single configuration using Docker Compose.

  • Running WordPress, MySQL and Nginx services with container architecture
  • Get a free SSL certificate with Let's Encrypt
  • Provide uninterrupted HTTPS by automatically renewing SSL certificates

Technical Summary

This guide explains how to install WordPress using Docker Compose on Ubuntu.
Instead of manual LAMP/LEMP installations; The database, application and web server are run in isolation through containers.

The installation process includes these steps:

  • Nginx web server configuration
  • Managing environment variables with the .env file
  • Obtaining an SSL certificate
  • Automating the certificate renewal process

Step 1: Nginx Web Server Configuration

First, create the directory that will host the project and open the Nginx configuration file:

mkdir wordpress && cd wordpress
mkdir nginx-conf && nano nginx-conf/nginx.conf
  • These commands create the project folder and open the Nginx settings file for editing.

This configuration:

  1. Defines the domain name

  2. Redirects PHP requests to the WordPress container

  3. Meets SSL verification requests


Step 2: Defining Environment Variables

  1. Increase security by keeping sensitive data such as database information in the .env file:

nano .env

Sample content:


MYSQL_ROOT_PASSWORD=parolaniz
MYSQL_USER=wp_kullanici
MYSQL_PASSWORD=wp_sifre

⚠️ Important:

  1. Be sure to add the .env file into .gitignore.
  • In this way, your passwords will not be shared accidentally.

Step 3: Starting Services with Docker Compose

  • The following services are defined in the docker-compose.yml file:
  1. MySQL (db)

  2. WordPress (PHP-FPM)

  3. Nginx (webserver)


nano docker-compose.yml

  • This file:
  1. Select the Docker images to be used

  2. How the services will communicate with each other

  3. Determines volume and network structures.


To initialize the entire infrastructure:


docker-compose up -d
  • This command publishes the WordPress environment in one go.

Step 4: SSL Certificate and Automatic Renewal

  1. By obtaining a free SSL certificate with Let's Encrypt, your site is published over HTTPS.
  • First a staging certificate is created, then a live certificate is created.

Create a script for automatic renewal of certificates:


nano ssl_renew.sh
chmod +x ssl_renew.sh

  • This script:
  1. Checks the certificate duration

  2. Automatically renews if necessary

  • Reloads Nginx without interruption

Add to cron:


sudo crontab -e

  • Add to the end of the file:

0 12 * * * /home/kullanici/wordpress/ssl_renew.sh
  • This task performs an automatic certificate check every day.

Frequently Asked Questions (FAQ)

1. If I stop the containers, will my data be deleted? No. Thanks to the volume structure, data is permanent on the server disk.

2. Can I use Apache instead of Nginx? Yes, but Nginx is lighter and more performant in Docker environments.

3. Why use PHP-FPM for WordPress? Nginx cannot run PHP directly. PHP-FPM takes over this task.

4. How do I connect my domain? Simply add an A record to the server IP address from the domain panel.


ProblemPossible CauseSolution
Connection refusedFirewall offOpen ports 80 and 443
Database error.env information is incorrectCheck information
Failed to obtain SSLDNS not propagatedVerify domain redirect

Result

With this guide, you have established a secure, portable and high-performance WordPress infrastructure on Docker.

🚀 You can go live this structure within minutes on the GenixNode infrastructure.