Setup Wordpress Debug Environment With Docker and Xdebug

It's a common practice to debug PHP using Xdebug. Xdebug is an extension for PHP to assist with debugging and development. 

In this article, I'm going to introduce a more convenient way to quickly set up development environment with PHPStorm, Docker, Docker compose and Xdebug.  The source code for docker compose configs are available in the Github: https://github.com/liqili/wordpress-xdebug-docker/ 

First of all, suppose we have installed Docker and Docker compose in a Linux-like OS, and installed a Wordpress site in production. Then, what we need to do is to setup a development environment for that site so that we can customize plugins or what else. This post will help you learn how to:

docker-compose.yml for container management

YAML

Customize Dockerfile for Apache Web Server

We need to download Xdebug source code and prepare a customized php.ini and dockerfile:

Download the specific version Xdebug source code according to your php version, in this post I'm using php7.4, so I use xdebug-2.9.6(https://xdebug.org/files/xdebug-2.9.6.tgz).

 Dockerfile for php apache web server(please modify php.ini and xdebug location accordingly):

Dockerfile


Customize php.ini by adding the following lines to enable xdebug.

Plain Text

Configure your IDE(PHPStorm)

I get used to JetBeans IDEs, so I will only use PHPStorm to illustrate how to configure you IDE. For other IDEs, there are a lot of manuals available that can help with the Xdebug configuration. 

Xdebug configuration

Finally, we need to install browser debug toolbar. Once installed, configure the option to set IDE Key to PHPSTORM. 

IDE key


You will be all set.  Then you can start the docker containers and start debug in your IDE.

Shell


 

 

 

 

Top