Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug in PHPStorm with built in webserver using Symfony command line tool

Tags:

I was able to set up a php web app debugger in PHPStorm by simply tying it to my localhost at a specific port and everything works fine. However for that to work I need to first run this command on the shell:

php app/console server:run --env=dev 

This works just fine if I set up breakpoints for browsing the site itself or testing api calls from a browser based rest client like postman

However I'm trying to actually set breakpoints for my mobile app (the mobile app sends http calls to the backend app which is a symfony app). Using the web app configuration doesn't work for this one.

Using this tutorial I was able to incorporate the above command line into PHPStorm, so now I can actually run the code using phpstorm command line tools.

My question is: How can I actually tie the debugger to the command line within PHPStorm? right now when I create a built-in web server in PHPStorm it defaults to using the default php interpreter (i.e If I run the code using the built in web server.. I see this in PHPStorm's console:

/usr/local/Cellar/php54/5.4.28/bin/php -S localhost:8000 -t /project/root/directory 

What I want instead is something like this:

php app/console server:run --env=dev -S localhost:8000 -t /project/root/directory 

Any idea how to do that?

like image 959
abbood Avatar asked May 14 '14 05:05

abbood


People also ask

How do I debug using xdebug?

You can find it in the extension window and install it. After installation, you must reload the VSCode window. Now, again run phpinfo(); method in any PHP file to check if Xdebug is enabled or not. Now click on the debug console tab and click on add configuration.

How do I use breakpoints in PhpStorm?

Set method breakpointsClick the gutter at the line where the method is declared. Alternatively, place the caret at the line and press Ctrl+F8 . Alternatively, do the following: Press Ctrl+Shift+F8 or select Run | View Breakpoints from the main menu.

How do I debug PHP API?

To debug PHP HTTP requests in PhpStorm, you can use the following methods: Compose and debug the request via the HTTP client in the code editor, which is the recommended approach. Use the PHP HTTP Request run configuration. Based on the configuration settings, PhpStorm composes the request to run.


Video Answer


1 Answers

You shouldn't create a run configuration at all, just to click on the listen button:

  1. Configure xdebug to attempt to debug every single script (xdebug.remote_autostart = 1 and xdebug.remote_enable = 1).

  2. Use "Phone handle" icon in IDE to start listening for debug connections (e.g. as described in here)

  3. Launch your php code from anywhere -- XDebug will attempt to debug every incoming request.

Here is an hour long webinar about the subject.

bonus

if you're interested in doing the same thing on vi + xdebug, see this answer.

like image 109
abbood Avatar answered Oct 22 '22 05:10

abbood