Install WordPress + xdebug using docker (mac/linux)
Posted date: Jun 25, 2022
This tutorial will explain how to install WordPress locally using docker.
Before you try this you need to make sure that you have docker installed in your system.
Create your project folder
mkdir wordpress-docker
Clone wpdiares/wordpress-xdebug
wp-diares/wordpress-xdebug using the official WordPress docker image and includes an extra configuration to enable xdebug which is a great tool that allows us to debug our custom code during development.
cd wordpress-docker
git clone https://github.com/wpdiaries/wordpress-xdebug.git xdebug
Create and edit docker-compose.yml
nano docker-compose.yml
version: '3.8'
services:
wordpress:
container_name: wordpress-wpd
restart: always
build:
dockerfile: Dockerfile # this line is actually redundant here - you need it only if you want to use some custom name for your Dockerfile
context: ./xdebug # a path to a directory containing a Dockerfile, or a url to a git repository
ports:
- "80:80"
environment:
VIRTUAL_HOST: mydomain.com, www.mydomain.com
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: mydbname
WORDPRESS_DB_USER: mydbuser
WORDPRESS_DB_PASSWORD: mydbpassword
# Set the XDEBUG_CONFIG as described here: https://xdebug.org/docs/remote
#For xdebug2 use remote_host
# If you are using mac client_host = host.docker.internal
XDEBUG_CONFIG: client_host=192.168.1.2
depends_on:
- db
volumes:
#this will create a www folder in wordpress-docker folder with your wordpress installation
- ./www:/var/www/html
networks:
- backend-wpd
- frontend-wpd
db:
container_name: mysql-wpd
image: mysql:8.0.20
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: mydbrootpassword
#MYSQL_RANDOM_ROOT_PASSWORD: '1' # You can use this instead of the option right above if you do not want to be able login to MySQL under root
MYSQL_DATABASE: mydbname
MYSQL_USER: mydbuser
MYSQL_PASSWORD: mydbpassword
ports:
- "3306:3306" # I prefer to keep the ports available for external connections in the Development environment to be able to work with the database
# from programs like e.g. HeidiSQL on Windows or DBeaver on Mac.
volumes:
- /opt/projects/wpd/mysql:/var/lib/mysql
networks:
- backend-wpd
networks:
frontend-wpd:
backend-wpd:
Edit hosts
You need to edit your hosts file and add the domain you specified in VIRTUAL_HOST
in docker-compose.yml
.
nano /etc/hosts
127.0.0.1 mydomain.com
Start docker and deploy containers
In your terminal type the following to start docker and deploy containers.docker-compose up -d
Now open your browser visit the domain you specified and you should see the WordPress installation page