Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to debug this application in PhpStorm #1

Open
dzschille opened this issue Feb 9, 2018 · 6 comments
Open

How to debug this application in PhpStorm #1

dzschille opened this issue Feb 9, 2018 · 6 comments

Comments

@dzschille
Copy link

dzschille commented Feb 9, 2018

My steps how i could debug the app:

First consideration: in phpdocker/php-fpm/php-ini-overrides.ini i set xdebug.remote_port to 9000 which is xdebugs default.
An other option would be to change the port in PhpStorms debug configuration.

How to start the app:

composer install

docker-compose up -d
  • Open the app in the browser: http://localhost:8074/
  • With a browser extension enable debugging.
  • In PhpStorm open the project.
  • In PhpStorm click "Start Listening for PHP debug connections".
  • Reload the page in the browser.
  • Now PhpStorm reacts and tells you that you should set up the server. If there is no reaction, check if your local IP as seen from the webserver container:
        ## open console in webserver and view your host IP
        docker-compose exec webserver /bin/sh -c "/sbin/ip route|awk '/default/ { print \$3 }'"

Now take this IP and set it in docker-compose.yml as value XDEBUG_CONFIG. Then you have to stop your docker containers and start them with docker-compose up -d again. You have to use "up" because "start" does not handle the config change.

  • Set the server name according to the one you have set as env var in docker-compose.yml. Als set the path mapping. The project root to /application is sufficient:
    debugging-1-configure-server
  • Now you can debug the code:
    debugging-2-stepping
  • You can also set break points:
    debugging-3-break-point
  • Here a screenshot where you can change the xdebug port, if you want to listen to another one than 9000:
    debugging-4-phpstorm-debug-config
@programetica
Copy link
Owner

@dzschille Thanks! I feel like I'm almost there. I went back and started fresh from your instructions without doing any of the Docker integration stuff in IntelliJ. I followed your instructions and it's not working for me yet -- one thing I notice in my IntelliJ is that when I click on the "Start listening for PHP Debug Connections" button, the square "Stop" button next to it doesn't turn red as it does in your IDE.

I'm going to research that and see what might be going on. I may be missing a setting or something.

@dzschille
Copy link
Author

dzschille commented Feb 10, 2018

@Holodny when I click on the "Start listening for PHP Debug Connections" button, the square "Stop" button next to it doesn't turn red directly. It turns red when the debug session started, so after reloading the web page and the reaction of PhpStorm.
Perhaps it has to do with the IDE? Download a test version of PhpStorm, so you can check if it has to do with IntelliJ or it's settings.

I also updated my HowTo: when you have changed to Xdebug remote host IP in your docker-compose.yml, you have to start the containers with docker-compose up -d, "start" is not enough.

You can verify if the setting is active like this:

## open console in php container and print env var
docker-compose exec php-fpm bash -c 'echo $XDEBUG_CONFIG'

@programetica
Copy link
Owner

programetica commented Feb 12, 2018

@dzschille Ok, I tried it with PHPStorm and had the same results with a new project. I'm going to try some simpler projects with just PHP & maybe Apache and no configuration changes and see how that works. I'll update here and at the phpdocker.io repository with my results. Thanks so much Dzschille!

@dzschille
Copy link
Author

@Holodny , i don't think it has to do with the project code. When no debug session starts it has mostly to do with the Xdebug config, and the IP to connect back. Have you checked your IP in the webserver container?:
docker-compose exec webserver /bin/sh -c "/sbin/ip route|awk '/default/ { print \$3 }'"
Is it the same you have set in your docker-compose.yml?

@programetica
Copy link
Owner

programetica commented Feb 12, 2018

@dzschille , Yah, I did that and added that IP to the yml file as in your example. I went through your instructions step by step for PHPStorm. I may be missing something. I'm looking at where other people have mentioned aliasing the host IP address also.

@dzschille
Copy link
Author

dzschille commented Feb 14, 2018

@Holodny if you use docker on mac you can use docker.for.mac.host.internal as alias fir your host IP address, see here. If you use linux you can not use that. However, you can check your IP like this:
docker-compose exec webserver /bin/sh -c "/sbin/ip route|awk '/default/ { print \$3 }'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants