How to Run WordPress Locally with Docker (Easy Setup Guide!) MariaDb, PhpMyAdmin
Learn how to run WordPress locally using Docker, MariaDB, and phpMyAdmin – the modern and hassle-free way to set up a WordPress development environment without installing everything manually. Perfect for developers, freelancers, or anyone wanting to build WordPress projects locally.
Setting Up WordPress with Docker: A Complete Guide
Prerequisites
Before you begin, download and install Docker Desktop for your operating system.
Project Setup
Step 1: Create Your Project Structure
Create a new project folder and add two configuration files:
docker-compose.yml – Defines your Docker services
.env – Contains your environment variables
Step 2: Configure Environment Variables
Create a .env file in your project root with the following configuration:
# Database Configuration DB_ROOT_PASSWORD=password DB_NAME=wordpress DB_USER=root DB_PASSWORD=password # WordPress Configuration WP_PORT=8080 # phpMyAdmin Configuration PMA_PORT=8081
Important: Change the default passwords before deploying to production!
Step 3: Set Up Docker Compose
Create a docker-compose.yml file with the following configuration:
version: '3.8'
services:
db:
image: mariadb:latest
container_name: wordpress_db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
volumes:
- db_data:/var/lib/mysql
networks:
- wordpress_network
wordpress:
depends_on:
- db
image: wordpress:latest
container_name: wordpress_site
restart: unless-stopped
ports:
- "${WP_PORT}:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
volumes:
- wp_data:/var/www/html
networks:
- wordpress_network
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin:latest
container_name: wordpress_phpmyadmin
restart: unless-stopped
ports:
- "${PMA_PORT}:80"
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
networks:
- wordpress_network
volumes:
db_data:
wp_data:
networks:
wordpress_network:
driver: bridgeLaunch Your WordPress Site
Navigate to your project folder in the terminal and run:
docker-compose up -d
That’s it! Your WordPress environment is now running.
Access Your Services
Once the containers are up and running, you can access:
- WordPress site: http://localhost:8080
- phpMyAdmin: http://localhost:8081
- Website files: \\wsl.localhost\docker-desktop\tmp\docker-desktop-root\var\lib\docker\volumes\YOUR_WEBSITE_wp_data_data\
Update Max Upload File Size
If you try to upload a plugin or a theme you might get the message “The uploaded file exceeds the upload_max_filesize directive in php.ini”. To fix that, open your .htaccess file and include the following two lines:
php_value upload_max_filesize 500M php_value post_max_size 500M
Remove the Containers
If you messed up, or you no longer want the containers you can run the following command to remove them. Note that this will delete containers and your data.
docker-compose down --volumes
What’s Included
This setup provides you with:
- MariaDB: A robust database server for WordPress
- WordPress: The latest version of WordPress, ready to configure
- phpMyAdmin: A web interface for managing your database
All services are connected through a dedicated Docker network and use persistent volumes to store your data safely.
Support This Work
If you found this guide helpful, consider supporting me with a small donation. Your contribution helps me keep these tutorials up to date and create more quality content.
Scan to donate