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: 

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:

  • Use Docker compose to mange docker containers.
  • Export production db to dev Mysql docker container.
  • Integrate Xdebug plugin with docker container as well as PHPStorm.
  • How to initialize MySQL container with sql script file. 

docker-compose.yml for container management

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(

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

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

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.

Source link

Write A Comment