4

I can't get my PhpStorm IDE to work with xdebug.

My current setup is the following:

  • PhpStorm 2017.1.4
  • MacOS Sierra 10.12.5

Here are the steps that I followed.

I have installed php with the following command. I have added the postgres parameter because I need it later to connect to a PostgreSQL database.

brew install php71 --with-postgresql

The next step is to install XDebug with the following command

brew install php71-xdebug

So the next step that I got from the documentation (https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html) is to edit the php.ini file with the following content:

[Xdebug]
zend_extension="<path to php_xdebug.dll>"
xdebug.remote_enable=1
xdebug.remote_port="<the port for Xdebug to listen to>" (the default port is 9000)
xdebug.profiler_enable=1
xdebug.profiler_output_dir="<AMP home\tmp>"

Just some questions about those fields and XDebug.

  • So I guess XDebug is some kind of service that runs on the remote_port and that PhpStorm is using to write data to? Or do you have to specify the port where the application you want to test is running?
  • What exactly is the profiler thing? And can the output dir be anything I can choose?

So this is my php.ini file that I think it should be:

[xdebug]
zend_extension="/usr/local/Cellar/php71-xdebug/2.5.4/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/usr/tmp"

That's it for the php.ini. So I have to check the settings in my PhpStorm IDE. And those are the following:

Settings in PhpStorm 1

Settings in PhpStorm 2

Settings in PhpStorm 3

So that is my setup. In my project I just have one index.php with <?php echo phpinfo(); ?> I just click the Chrome icon so it opens directly in the browser to check if XDebug is there. I see the following result.

Screenshot phpinfo

So I thought to myself ok let's try some debugging. So I changed my index.php file to the following

$i = 2;
$j = $i + 2;
echo $j

I've put a breakpoint on the 2nd line. And when I run it, it never stops at the breakpoint. What is needed to do that or am I wrong in my configuration somewhere?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
koala
  • 1,544
  • 1
  • 20
  • 33
  • 1
    Answering your question about how XDebug connects during remote debug. When your app is running with XDebug configured, it's connects to `remote_host`:`remote_port` and sends data there. So, PHPStorm here is a service who listens for XDebug connection – Sergei Kasatkin Jun 07 '17 at 13:47
  • 2
    The first section of [this answer](https://stackoverflow.com/a/39095146/4265352) explains how an XDebug session works. – axiac Jun 07 '17 at 13:49
  • you will need `xdebug.idekey=PHPStorm` and `xdebug.remote_mode=req` in your .ini file and then start listening to PHP Debugging Connection in PHP Storm. And also to start from the browser the Xdebug helper. – Edwin Jun 07 '17 at 13:52
  • Thanks @axiac, that gives some better insight in how it works – koala Jun 07 '17 at 14:14
  • @Edwin Thanks for the tip about the XDebug Chrome extension that made it work. Didn't need to include the 2 extra php.ini lines... – koala Jun 07 '17 at 14:15
  • do you use php-fpm in your stack ? If yes, change the port 9000 which is also the default port for fpm. Also, you should have a xdebug.log somewhere, and look there to see what is happening. If you configure a xdebug.log, absolutely make certain that the apache process (_www:_www) has write privileges to that. Finally, if you are using this to create/test a restful api, bump up the number of simultaneous connections. – YvesLeBorg Jun 07 '17 at 15:16

1 Answers1

0

To make Xdebug remote debugging working on your page, you need to set a cookie in your browser, telling the server you want to debug the page, there are many extensions for that, the most known is Xdebug helper in Chrome.

I also suggest you to follow this tutorial Zero-configuration debugging, it is very detailed and clear IMO.

If you still have problems i'll try to help you with pleasure :)

Gramatiik
  • 122
  • 1
  • 11