Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug PHP cli application inside docker with PhpStorm

I have troubles with setting up debugging php cli application. I work on Mac OS and I have here Vagrant with Ubuntu inside, and inside this Ubuntu I have docker. So one of the docker containers runs my php application, where the PHP interpreter lives.

Before (when the application was exactly in Vagrant machine) I was using this command to debug my cli applications, but now it does not work.:

export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=192.168.10.10 remote_connect_back=0"

How can I set up PhpStorm to debug my php cli app ?

like image 643
Albert Tobac Avatar asked Aug 31 '25 01:08

Albert Tobac


2 Answers

Inside of your Docker container don't use remote_host. Also, you don't have to expose any additional ports in Docker or in Vagrant.

Here is my xdebug.ini file that works with PHP 5.6

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_connect_back=1

Make sure that PhpStorm (2016.1 in my case) is configured correctly

  • Languages & Frameworks -> PHP -> Servers -> localhost -> localhost : 80 Xdebug
  • Languages & Frameworks -> PHP -> Debug -> Xdebug -> Debug port: 9000
  • Languages & Frameworks -> PHP -> Debug -> Xdebug -> Can accept external connections
  • Languages & Frameworks -> PHP -> Debug -> DBGp Proxy -> Port 9000

Once this is done find Listen for debugger connections icon in PhpStorm in the toolbar and click it.

If you want to call it from a command line remember to include XDEBUG_SESSION cookie, i.e.

curl 'http://localhost' -sSLI -H 'Cookie: XDEBUG_SESSION=xdebug'

If you use Firefox install The easiest Xdebug and enable it in the toolbar.

like image 86
Daniel Stefaniuk Avatar answered Sep 02 '25 17:09

Daniel Stefaniuk


In my case, debugging through web browsers worked well, the problmes came with CLI debugging (phpunit). This is because xdebug get lost with path mappings and you need to explicit tell docker.

You need to tell Docker which server configuration in PHPStorm should use, just export that env variable inside your docker container.

export PHP_IDE_CONFIG="serverName=<server-name>"
like image 22
José Lozano Hernández Avatar answered Sep 02 '25 15:09

José Lozano Hernández