Search code examples
ubuntuphpstormxdebug

Xdebug installation and setup


I have moved everything to a different server and everything is running successfully except today (and I have spent ALL day) I have attempted the wholly dreaded task of setting up XDebug.

I have read the instructions and gone through them 3 times. I note it now ends with the very unhelpful

Please also update php.ini files in adjacent directories, as your system seems to be configured with a separate php.ini file for the web server and command line.

I have finally got it to appear in my phpinfo however it does not seem to connect, and I cannot see it listening on the port

enter image description here

At

/etc/php/8.1/fpm/conf.d/99-xdebug.ini

and

/etc/php/8.1/fpm/php.ini

I have

[xdebug]
zend_extension = /usr/lib/php/20210902/xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
;xdebug.client_host = 127.0.0.1
xdebug.log = "/var/log/xdebug.log"
xdebug.idekey = PHPSTORM
#[/xdebug]#

On PHPStorm (which I don't think is the issue as it was working on previous server) enter image description here

I have added xdebug_info() to start of php code and now getting this output

enter image description here

log shows

[1147] Log opened at 2023-07-16 15:22:03.120035
[1147] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[1147] [Step Debug] WARN: Creating socket for 'localhost:9003', poll success, but error: Operation now in progress (29).
[1147] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).
[1147] Log closed at 2023-07-16 15:22:03.121645

Additionally I can see phpstorm listening with enter image description here enter image description here

Access is only via SSH, in putty I have

enter image description here

How can I troubleshoot this further please


Solution

  • Xdebug does not listen. It is the IDE that must listen for incoming connections from Xdebug. It is therefore normal that you seen nothing listening until you enable "Listen for Connections" in PhpStorm.

    If it shows up in phpinfo() then it will be loaded. If you use xdebug_info() it tells you which modes are enabled as well. And because you have start_with_request turned on, it will also tell you whether it made a successful connection to your IDE, or if not, why not. Each warning/error messages in the Diagnostics Log has a link to documentation with further information.

    To see even more diagnostics information, that, when you read it should clarify what is going on, enable xdebug.log=/tmp/xdebug.log and xdebug.log_level=10 in php.ini. These settings will, after restarting your webserver, also reflect in the xdebug_info() output.