Run xdebug from command line
Question
Is ist possible to run bin/magento s:up with xdebug on ?
I have tried the following:
-
run directly via terminal bin/xdebug enable bin/magento s:up (with breakpoint set) -> Doesn' stop at breakpoint
-
add php script in phpstorm
- File: src/bin/magento
- Arguments: s:up
- Interpreter: markoshust/magento-php:7.3-fpm-18 -> Throws an error: Connetion to redis:6379 failed after 2 failures.Last Error : (1) php_network_getaddresses: getaddrinfo failed: Name or server not known -> Redis is up and running on port 6379 based on docker ps
XDEBUG via browser works fine, everything is set up as documented.
Thank you for your input
Yea let's keep this issue open... this has been requested a few times. I haven't looked into this because I've never had to do this, but if someone wants to chime in with instructions on how to set this up, that would be greatly appreciated.
In the end it is a simple configuration step:
- PHPStorm->Preferences
- PHP -> Path Mappings
- src -> /var/www/html
After that set up a new Run Configuration:
- Run -> Edit Configurations
-
- PHP Script
- File: src/bin/magento
- Arguments: s:up (f.e. , can be any bin/magento cli command)
- Interpreter: Docker Composer phpfpm setup previously based on your documentation
- ^D (on mac) to start the Run
- XDEBUG stops at Breakpoint
- Profit
Integration Tests can be debugged with this configuration as well.
@Cloudy777 thanks a ton for this, I created a new video lesson for it in the course https://courses.m.academy/courses/set-up-magento-2-development-environment-docker/lectures/36677538
@markshust - Thank you for the instructions, but how can we do the same thing in VSCode.
Good idea @malikabid -- I'll test and add a video for this.
Hi @markshust
Today I was able to do the debugging from command line including bin/magento and integration tests.
I just added the link in docker-compose.dev.yml
environment: XDEBUG_CONFIG: "idekey=VSCODE client_host=host.docker.internal client_port=9003"
and restarted the containers (bin/restart)
Appreciate it @malikabid, I re-opened this ticket so we could potentially add this info either to the README or to the docker-compose.dev.yml file itself.