Debug your PHP with Docker and xDebug from PHPStorm

Last time we have talked about how you can enable Docker and work with it via PHPStorm, today I’ll try to explain how you can debug your app using Docker from within PHPStorm using xDebug.

First of all you must have your PHP image up and running, but sadly you cant use the official one, you will need to build your own image, you can use this small script that I have wrote

basically this Dockerfile will pull the image php:7-fpm and use it as our base image, then we will update and clean the system then install some libraries (PS: this is what I used for my laravel project, but it will work with any normal php project you have), then we will need to tell the system that we need to install xdebug using pecl ( line 8 ) , and from line 10 till line 13 , we are just configuring xdebug and make sure we add those info to be preloaded with our php instance.

on line 16, I copy the file php.ini to my php directory so I can overwrite the default php.ini information, so what does this php.ini contain, look at this :

as you can see, its only overwrite the information about the upload limitation and a very important value which is xdebug.remote_host this should contain your local machine IP , and in my case its .

Now we have our image ready to be built.

After building it, we need to tell PHPStorm how to debug our system, and so we will need to do the following:

1- Create a server and we can call it the name of our project , in my case its called jobsBoard and make sure that you are mapping the files correctly




2- We should configure out DBGp Proxy to use the same name we used for our server, in my case its jobsBoard and the port should be the port we specify for xDebug by default its 9000












3- Make sure that you are listing to PHP Debug connection before you run your docker, and if you have docker running before you do the configuration, you should restart it to take effect





4- set any breakpoint to your app like











and just refresh your app PHPStorm will prompt you with the debugger interface


Filed under: Linux, MySQL, PHP

No comment yet, add your voice below!

Add a Comment

Your email address will not be published. Required fields are marked *

Comment *

Name *
Email *