Xdebug not working after I install PHP and configure settings - php

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.

(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:
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:
And down below the configuration settings loaded:
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"

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

To install xdebug on php7.3 run the following commands:
sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3
Now download source code and install by running the following commands:
cd /tmp
wget http://xdebug.org/files/xdebug-2.8.0.tgz
tar -xzvf xdebug-2.8.0.tgz
cd xdebug-2.8.0
phpize
./configure
sudo make
sudo make install

Related

xdebug not working after ubuntu upgrade

today I upgraded ubuntu 14.10 to 15.04 and xdebug is not working anymore. I use eclipse Luna Service Release 2.
I've tried reinstalling xdebug through pecl, apt-get, even manual install following http://xdebug.org/wizard.php instructions (pasting my phpinfo() output).
I have xampp, in /opt/lampp directory.
I've tried several locations for "zend_extension" in /opt/lampp/etc/php.ini such as zend_extension=/usr/lib/php5/20131226/xdebug.so and zend_extension =/opt/lampp/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
When I hit debug on eclipse, the browser receives the order, and the parameters ?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY= are included in the url, but the execution will not stop on any breakpoint.
When I run phpinfo() xdebug is not showing as an installed module.
any hints?
I removed the phpinfo() output for clarification after posting the answer.
Finally I found no solution, so I had to remove all the lamp package, and I reinstalled everything as independent modules following this tutorial: http://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-15-10/, then I did this to install xdebug:
1.- Install xdebug extension for PHP
$ sudo apt-get install php5-xdebug
2.- Check the location of "xdebug.so" module, which is kept under "/usr/lib/php5/20131226", where the number depends on the PHP version.
3.- The installation creates a configuration file "/etc/php5/mods-available/xdebug.ini" with the following line (otherwise, create one):
zend_extension=xdebug.so
NOTE: in the previous version, you need to specify the full-path filename, e.g., "zend_extension=/usr/lib/php5/20121212/xdebug.so".
Include the following lines into "xdebug.ini" to enable remote debugging from Eclipse PDT:
xdebug.remote_enable = On
xdebug.remote_port = 9000
xdebug.remote_host = 127.0.0.1
Recall that Apache loads PHP configuration files "/etc/php5/apache2/php.ini" and "/etc/php5/apache2/conf.d/*.ini". To enable the above xdebug configuration file, create the following symlink in "/etc/php5/apache2/conf.d":
$ cd /etc/php5/apache2/conf.d
$ sudo ln -s ../../mods-available/xdebug.ini 20-xdebug.ini
$ ls -l
lrwxrwxrwx 1 root root 31 Sep 11 19:42 20-xdebug.ini -> ../../mods-available/xdebug.ini
4.- Check PHP configuration file "/etc/php5/apache2/php.ini" for the following settings:
; Turn on the error display for development system,
; but not for production system.
display_errors = On
; Format error in HTML
html_errors = On
5.- Restart the Apache2:
$ sudo service apache2 restart
And it works like a charm
For now Xdebug (Please only use uptil Xdebug 2.6, because later versions had some issues with debugging); only work up to php 7.2 (i.e. less than 7.3). So if you had any other version installed like php 7.3 or 7.4 then you had to also install php 7.2 along side your current php version (mostly because now by default latest version is installed through apt). and then update in between alternatives.
To set PHP 7.0 as the default, run
update-alternatives --set php /usr/bin/php7.0
To set PHP 7.2 as the default, run
update-alternatives --set php /usr/bin/php7.2
To set PHP 7.3 as the default, run
update-alternatives --set php /usr/bin/php7.3
To set PHP 7.4 as the default, run
update-alternatives --set php /usr/bin/php7.4
Before we can configure Apache to use PHP 7.2, we need to disable the new (or old) version of PHP by typing
a2dismod php7.4
Now enable the newly installed PHP 7.2 version with the following command:
a2enmod php7.2
Restart the Apache web server for the changes to take effect:
sudo systemctl restart apache2

Problems installing xdebug.so extension on local AMP environment

Edit: I've now removed the version of xdebug.so I installed manually, and installed XDebug via Homebrew. When I type "php -i" at the command line, xdebug appears to be installed; but when I run phpinfo(), there's still no sign of XDebug.
I've just got a new Mac so, like every time I buy a new Mac, I have rebuilt my local web development environment (this time, following an amazing tutorial: https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew)
Everything has gone smoothly until I got to installing the XDebug extension. I use Komodo as a development environment so, as I've always done in the past, I followed the instructions here: http://docs.activestate.com/komodo/7.1/debugphp.html#debugphp_top
I followed the instructions to the letter, but I can't get xdebug.so to appear in my phpinfo.php() page. Here's what I did:
Created a phpinfo.php file so that I can find the correct php.ini file
Checked that phpinfo.php file and found that the "Loaded Configuration File" is "/usr/local/etc/php/5.6/php.ini"
Edited that php.ini, adding the following lines to the bottom of the file:
_
zend_extension=/usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=<idekey>
; You may also want this - to always start a remote debugging connection.
;xdebug.remote_autostart=1
Ran "brew services restart httpd22" (and, just to be sure, "sudo apachectl restart")
When I go reload phpinfo.php, it contains to reference to xdebug.so.
I can confirm that xdebug.so is present at /usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226 and that /usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226 is set as the "extension_dir" in php.ini.
What am I missing?!
Ultimately this proved be to be caused my me doing things in the wrong order. I'd used Homebrew to install Apache and PHP, but I'd installed Apache 2nd: this meant that it wasn't set up to work with the version of PHP I then installed.
I reinstalled PHP using the command brew reinstall php54 --homebrew-apxs, and that ensured that Apache and PHP were talking to each other.
Then, to install xdebug, I ran brew install homebrew/php/php56-xdebug. After restarting Apache, XDebug showed up in phpinfo() straight away!
Then I had to get XDebug talking to Komodo. To do this I added in the config lines from my original post to the specific xdebug config file that had been created during the Homebrew install (mine was located at /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini), and then made sure that Komodo was listening on the correct port (9000 didn't work, so I changed to 9001).

How to disable XDebug

I think that my server became slow since I installed XDebug.
So, in order to test my hypothesis I want to disable XDebug completely.
I've been searching for tutorials on how to do this but I can't find such information.
Find your php.ini and look for XDebug.
Set xdebug autostart to false
xdebug.remote_autostart=0
xdebug.remote_enable=0
Disable your profiler
xdebug.profiler_enable=0
Note that there can be a performance loss even with xdebug disabled but loaded. To disable loading of the extension itself, you need to comment it in your php.ini. Find an entry looking like this:
zend_extension = "/path/to/php_xdebug.dll"
and put a ; to comment it, e.g. ;zend_extension = ….
Check out this post XDebug, how to disable remote debugging for single .php file?
An easy solution working on Linux distributions similar to Ubuntu
sudo php5dismod xdebug
sudo service apache2 restart
In Linux Ubuntu(maybe also another - it's not tested) distribution with PHP 5 on board, you can use:
sudo php5dismod xdebug
And with PHP 7
sudo phpdismod xdebug
And after that, please restart the server:
sudo service apache2 restart
Also, you can add xdebug_disable() to your code. Try:
if(function_exists('xdebug_disable')) { xdebug_disable(); }
I renamed the config file and restarted server:
$ mv /etc/php/7.0/fpm/conf.d/20-xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini.bak
$ sudo service php7.0-fpm restart && sudo service nginx restart
It did work for me.
Comment extension in php.ini and restart Apache. Here is a simple script (you can assign shortcut to it)
xdebug-toggle.php
define('PATH_TO_PHP_INI', 'c:/xampp/php/php.ini');
define('PATH_TO_HTTPD', 'c:/xampp/apache/bin/httpd.exe');
define('REXP_EXTENSION', '(zend_extension\s*=.*?php_xdebug)');
$s = file_get_contents(PATH_TO_PHP_INI);
$replaced = preg_replace('/;' . REXP_EXTENSION . '/', '$1', $s);
$isOn = $replaced != $s;
if (!$isOn) {
$replaced = preg_replace('/' . REXP_EXTENSION . '/', ';$1', $s);
}
echo 'xdebug is ' . ($isOn ? 'ON' : 'OFF') . " now. Restarting apache...\n\n";
file_put_contents(PATH_TO_PHP_INI, $replaced);
passthru(PATH_TO_HTTPD . ' -k restart');
in xubuntu I totally disabled xdebug for the CLI with this...
sudo rm /etc/php5/cli/conf.d/*xdebug*
On Windows (WAMP) in CLI ini file:
X:\wamp\bin\php\php5.x.xx\php.ini
comment line
; XDEBUG Extension
;zend_extension = "X:/wamp/bin/php/php5.x.xx/zend_ext/php_xdebug-xxxxxx.dll"
Apache will process xdebug, and composer will not.
If you are using php-fpm the following should be sufficient:
sudo phpdismod xdebug
sudo service php-fpm restart
Notice, that you will need to tweak this depending on your php version. For instance running php 7.0 you would do:
sudo phpdismod xdebug
sudo service php7.0-fpm restart
Since, you are running php-fpm there should be no need to restart the actual webserver. In any case if you don't use fpm then you could simply restart your webserver using any of the below commands:
sudo service apache2 restart
sudo apache2ctl restart
Ubuntu 16.04 remove xdebug from PHP.
Find your php.ini file and make sure xdebug is there:
grep -r "xdebug" /etc/php/
This might come up with different versions, if so run php -v to find your version.
Edit the php.ini file, like:
sudo vi /etc/php/5.6/mods-available/xdebug.ini
Comment the line:
//zend_extension=xdebug.so
Save the file
Inspired by PHPStorm right click on a file -> debug -> ...
www-data#3bd1617787db:~/symfony$
php
-dxdebug.remote_enable=0
-dxdebug.remote_autostart=0
-dxdebug.default_enable=0
-dxdebug.profiler_enable=0
test.php
the important stuff is -dxdebug.remote_enable=0 -dxdebug.default_enable=0
Two options:
1: Add following code in the initialization Script:
if (function_exists('xdebug_disable')) {
xdebug_disable();
}
2: Add following flag to php.ini
xdebug.remote_autostart=0
xdebug.remote_enable=0
1st option is recommended.
Find your PHP.ini and look for XDebug.
normally in Ubuntu its path is
/etc/php5/apache2/php.ini
Make following changes (Better to just comment them by adding ; at the beginning )
xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.profiler_enable=0
then restart your server
again for Ubuntu
sudo service apache2 restart
Disable xdebug
For PHP 7: sudo nano /etc/php/7.0/cli/conf.d/20-xdebug.ini
For PHP 5: sudo nano /etc/php5/cli/conf.d/20-xdebug.ini
Then comment out everything and save.
UPDATE -- Disable for CLI only
As per #igoemon's comment, this is a better method:
PHP 7.0 (NGINX)
sudo mv /etc/php/7.0/cli/conf.d/20-xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini.old
sudo service nginx restart
Note: Update the path to your version of PHP.
I created this bash script for toggling xdebug. I think it should work at least on Ubuntu / Debian. This is for PHP7+. For PHP5 use php5dismod / php5enmod.
#!/bin/bash
#
# Toggles xdebug
#
if [ ! -z $(php -m | grep "xdebug") ] ; then
phpdismod xdebug
echo "xdebug is now disabled"
else
phpenmod xdebug
echo "xdebug is now enabled"
fi
# exit success
exit 0
I ran into a similar issue. Sometimes, you wont find xdebug.so in php.ini. In which case, execute phpinfo() in a php file and check for Additional .ini files parsed. Here you'll see more ini files. One of these will be xdebug's ini file. Just remove (or rename) this file, restart apache, and this extension will be removed.
I had following Problem:
Even if I set
xdebug.remote_enable=0
Xdebug-Error-Message-Decoration was shown.
My solution:
xdebug.default_enable=0
Only if I use this Flag, Xdebug was disabled.
(This is for CentOS)
Rename the config file and restart apache.
sudo mv /etc/php.d/xdebug.ini /etc/php.d/xdebug.ini.old
sudo service httpd restart
Do the reverse to re-enable.
Since xdebug 3 came out the settings in pnp.ini have slightly changed.
Setting:
xdebug.mode=off
Will disable all processing According to the docs:
Nothing is enabled. Xdebug does no work besides checking whether
functionality is enabled. Use this setting if you want close to 0
overhead.
Disable xdebug only for certain PHP version or sapi.
On this case PHP 7.2 fpm
sudo phpdismod -v 7.2 -s fpm xdebug
sudo service php7.2-fpm nginx restart
You can disable Xdebug on PHP CLI on runtime using the -d flag:
php -d xdebug.mode=off -i | grep xdebug.mode
Result: xdebug.mode => off => off
Example, running unit tests with Xdebug disabled, so it's faster:
php -d xdebug.mode=off ./vendor/bin/phpunit
You can also create an alias for it to make it easier to use.
If you are using MAMP Pro on Mac OS X it's done via the MAMP client by unchecking Activate Xdebug under the PHP tab:
So, yeah, all what you need, just comment line in INI file like zend_extension=xdebug.so or similar.
Comments can be made by adding semicolon.
But, such kind of answer already added, and I'd like to share ready solution to switch Xdebug status.
I've made quick switcher for Xdebug. Maybe it would be useful for someone.
Xdebug Switcher
For WAMP, click left click on the Wamp icon in the taskbar tray. Hover over PHP and then click on php.ini and open it in your texteditor.
Now, search for the phrase 'zend_extension' and add ; (semicolon) in front it.
Restart the WAMP and you are good to go.
Apache/2.4.33 (Win64) PHP/7.2.4 myHomeBrew stack
At end of php.ini I use the following to manage Xdebug for use with PhpStorm
; jch ~ Sweet analizer at https://xdebug.org/wizard.php for matching xdebug to php version.
; jch ~ When upgrading php versions check if newer xdebug.dll is needed in ext directory.
; jch Renamed... zend_extension = E:\x64Stack\PHP\php7.2.4\ext\php_xdebug-2.6.0-7.2-vc15-x86_64.dll
zend_extension = E:\x64Stack\PHP\php7.2.4\ext\php_xdebug.dll
; jch !!!! Added the following for Xdebug with PhpStorm
[Xdebug]
; zend_extension=<full_path_to_xdebug_extension>
; xdebug.remote_host=<the host where PhpStorm is running (e.g. localhost)>
; xdebug.remote_port=<the port to which Xdebug tries to connect on the host where PhpStorm is running (default 9000)>
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.profiler_output_dir="E:\x64Stack\Xdebug_profiler_output"
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1
; jch ~~~~~~~~~To turn Xdebug off(disable) uncomment the following 3 lines restart Apache~~~~~~~~~
;xdebug.remote_autostart=0
;xdebug.remote_enable=0
;xdebug.profiler_enable=0
; !!! Might get a little more speed by also commenting out this line above...
;;; zend_extension = E:\x64Stack\PHP\php7.2.4\ext\php_xdebug.dll
; so that Xdebug is both disabled AND not loaded
For those interested in disabling it in codeship, run this script before running tests:
rm -f /home/rof/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
I was receiving this error:
Use of undefined constant XDEBUG_CC_UNUSED - assumed 'XDEBUG_CC_UNUSED' (this will throw an Error in a future version of PHP)
which is now gone!
In CLI:
sudo phpdismod xdebug
disable xdebug
sudo phpenmod xdebug
enable xdebug
And restart the server

Install XDebug and load in Acquia Drupal Stack?

I am trying to follow this article:
http://robshouse.net/article/xdebug-komodo-and-acquia-drupal-stack-installer
I did all of that, yet XDebug is still not being loaded or shown on phpinfo.
Has anyone got this to successfully work?
I installed XDebug with Homebrews, brew install xdebug. I copied xdebug.so to my acquia stack folder, /php/ext/xdebug.so and added the approrpiate lines to php.ini, restarted the stack and Apache and no luck.
Tried a few different articles and have not had success.
My php.ini:
[debug]
; Remote settings
zend_extension=/Applications/acquia-drupal/php/ext/xdebug.so
xdebug.remote_autostart=off
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
This is reported in my apache errors:
Failed loading /Applications/acquia-drupal/php/ext/xdebug.so
But the file does exist there.
The author of robshouse.net moved his website to Drupal Gardens and did not migrate the article linked to in the question. However the article is somewhat outdated.
You do not need to download anything to enable xdebug in current versions of Acquia Dev Desktop.
Simply uncomment the line that mentions xdebug in /Applications/acquia-drupal/php5_*/bin/php.ini. There are three of these for PHP versions 5.2 5.3 and 5.4 respectively. Make the change in all of them (unless you know better).
You will need to stop and start Acquia Dev Desktop for the change to take effect.
For php -v 7.0.3 users:
ssh: Brew update && upgrade
ssh: brew install homebrew/php/php70-xdebug
ssh: php -m
Check that the module is installed. Then copy the entire
usr/local/Cellar/php70/7.0.3/ content to - >
Applications/DevDesktop/php7_0/
ssh: nano /usr/local/etc/php/7.0/php.ini
configure xdebug.so:
ssh: sudo cp /usr/local/etc/php/7.0/php.ini
/Applications/DevDesktop/php7_0/bin/
DONE :-)
I didn't get the XDebug to work either with Homebrew.
Get the working xdebug.so from ActiveState.
http://code.activestate.com/komodo/remotedebugging/
Article about this:
http://debuggable.com/posts/setting-up-xdebug-on-mac-os-x-or-win32-linux:480f4dd6-0240-4a90-8fa1-4e41cbdd56cb

How to get Xdebug to work on a Mac

I have spent a lot of time on this with no end product.
Installed MAMP.
Found "make" (was installed in different folder)
Installed autoconf which was missing so I can run phpize
Downloaded, compiled and installed xdebug according to:
http://www.xdebug.org/find-binary.php
Made necessary changes to correct php.ini.
Restarted MAMP - but phpinfo() does not show xdebug.
No matter what I do to the php.ini file located at /Applications/MAMP/conf/php5.3/php.ini, nothing changes. The site still loads fine. Even if I nuke it completely. Yet that is what phpinfo() shows it is loading.
What am I overlooking?
php.ini
[xdebug]
zend_extension=/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
The site where you can download precompiled binaries of xdebug had been down all morning (activestate) which is why I was trying to compile my own.
I just found out the site was back online, downloaded the xdebug.so file, and it is now loading.
Modern MACs have two kinds of binaries - 32-bit and 64-bit. Verify that you PHP matches your xdebug: do file Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so then file /path/to/mamp/Library/modules/php5.3/libphp5.so and see if they both show i386 or x86_64.
I just did it and it worked. Here is what I did:
install PECL in order to install Xdebug
download http://pear.php.net/go-pear.phar
in the download directory execute php -d detect_unicode=0 go-pear.phar
now add the ~/pear/bin folder to your path echo "export PATH=$PATH:/Users/the-user/pear/bin" >> .bash_profile
and make the change visible to your terminal . .bash_profile
install Xdebug
now that you have PECL it's as easy as sudo pecl install xdebug
now you need to add a line to php.ini
the php.ini on my mac (Lion) is /etc/php.ini.default
search for zend_extension and uncomment the line if it is correct or change it if it is not (in my case it was correct)
That's it. Unless you want to debug form IntelliJ Idea. In which case I had to copy /etc/php.ini.default to /etc/php.ini
have fun with PHP
Just to point out the obvious, but one that I keep throwing away time on; in an apache2 environment remember to restart apache2 for the changes to take effect.
sudo apachectl restart

Categories