Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xdebug not working after I install PHP and configure settings

Tags:

php

xdebug

I installed Xdebug on PHP 7.3 using pecl install xdebug

When I add these settings to /etc/php/7.3/apache2/php.ini and reload Apache the page fails and says no data sent to server.

xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.halt_level=E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE
xdebug.scream=1

Not sure why it's not working.

like image 383
somejkuser Avatar asked Nov 25 '25 23:11

somejkuser


2 Answers

(In the original version of your question, your configuration was commented out, now you've edited that bit out, leaving the next couple of paragraphs kinda out of the loop)

Despite the documentation stating that the has character (#) is no longer recognized as a valid comment character since PHP 7.0:

PHP Changelog

it seems that php will happily treat those lines as commented nonetheless in configuration files. Everything afer the hash is ignored by the interpreter.

So those configuration lines are completely ineffective.

To verify that your configuration is being loaded, create a simple file like this:

<php
phpinfo();

Loading this file will tell you everything about PHPs configuration. If Xdebug has been successfully loaded, you'll see something like this:

phpinfo output

And down below the configuration settings loaded:

phpinfo output

These are the most important settings, that actually load and enable the Xdebug extension:

zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1

Important: You need to check that /usr/lib/php/20180731/xdebug.so actually exists, and if not find the actual location of your xdebug module.

The next line assumes that the webserver and the browser are installed on the same machine on the same IP, which might be true for a simple setup:

 xdebug.remote_host=127.0.0.1

As an alternative, you can tell Xdebug to connect back to whichever IP has made the orginal request

 xdebug.remote_connect_back=On

With the following line you are telling on which port your IDE is listening to. It's 9000 by default, so you'll normally would not need to set it unless you need to listen to a non-standard port (e.g. debugging several projects at the same time, against different interpreters). But normally, you can omit this line safely:

xdebug.remote_port=9000

Once the module is loaded and enabled, you can also configure some Xdebug settings using an environment variable. Specifically xdebug.remote_host, xdebug.remote_port, xdebug.remote_mode and xdebug.remote_handler

E.g:

export XDEBUG_CONFIG="remote_host=192.168.0.3 remote_port=9005"
like image 81
yivi Avatar answered Nov 28 '25 13:11

yivi


  • xdebug is not compatible with php7.3 for releases < 2.7
  • you may install xdebug beta version which is make-compatible with php7.3:
pecl install xdebug-beta

https://bugs.xdebug.org/view.php?id=1584


Update:

XDEBUG has released a new version, and it has different configurations. The new version is compatible with PHP>=7.4. Check it out:

https://xdebug.org/docs/install

like image 27
wajdi_jurry Avatar answered Nov 28 '25 13:11

wajdi_jurry