This document describing how you can use Xdebug and PhpStorm within DEV environment.
Please follow PhpStorm documentation before actions described bellow.
1.Check /docker/dev/xdebug.ini (optional)
- In case you need debug only requests with IDE KEY: PHPSTORM from frontend in your browser:
xdebug.start_with_request = no
Install locally in Firefox extension "Xdebug helper" and set in settings IDE KEY: PHPSTORM
- In case you need debug any request to an api (by default):
xdebug.start_with_request = yes
2.Go to Settings -> Php -> Debug
and set Xdebug port 10000
3.Check your Run/Debug Configurations
as on image bellow
4.Install needed browser extensions (optional, see step 1). For example for Firefox install extension "Xdebug helper" and set in extension settings IDE KEY: PHPSTORM
After actions above you can start to listen incoming PHP debug connections:
- Add breakpoint to your code
- Enable Xdebug in your browser (optional, required only when xdebug.start_with_request = no)
- Click
Debug
button in PhpStorm - Reload browser page
If everything configured properly you will get something like next:
If you're using Postman to test/debug your application when xdebug.start_with_request = no
you need to add ?XDEBUG_SESSION_START=PHPSTORM
to each URL
that you use with Postman. If you have default configuration (xdebug.start_with_request = yes
) - nothing to do and your Xdebug should work out of the box.
If you want to debug console commands or messenger async handlers you just need to uncomment/edit option xdebug.client_host
in config docker/dev/xdebug.ini
:
xdebug.client_host=172.17.0.1
Just find out the proper host ip in your docker bridge configuration and set above option (in general it is 172.17.0.1
).
Don't forget to rebuild docker containers according to general documentation.
If you want to debug your messenger async jobs just follow next steps:
- Enter in
supervisord
docker container shell using your local shell commandmake ssh-supervisord
- In
supervisord
container shell run next commandsupervisorctl
- Stop program
messenger-consume:messenger-consume_00
using next commandstop messenger-consume:messenger-consume_00
and make sure that you can see messagemessenger-consume:messenger-consume_00: stopped
- Exit from supervisorctl shell using next command
exit
- Exit from
supervisord
docker container using commandexit
. Make sure that you are in local shell. - Enter in
symfony
docker container shell using your local shell commandmake ssh
- Put necessary message in queue or make sure that it is already there
- Run PHPStorm debug
- Run in
symfony
docker container shell next command in order to run your async handlers/usr/local/bin/php bin/console messenger:consume async_priority_high async_priority_low --limit=1
(where limit option is a number of messages that you want to debug) - Have fun with debugging and don't forget to switch on program
messenger-consume:messenger-consume_00
(step 1, 2 and executestart messenger-consume:messenger-consume_00
) insupervisord
docker container when you'll finish your debugging (or you can simply restart environment using your local shell commandmake restart
).