Check if xdebug is working
PhpXdebugPhp Problem Overview
Without installing a texteditor or an IDE, is it possible to test if xdebug is working, i.e. if it can debug php code?
The only part xdebug comes up in phpinfo() is the following:
> Additional .ini files parsed /etc/php5/apache2/conf.d/mysql.ini, > /etc/php5/apache2/conf.d/mysqli.ini, /etc/php5/apache2/conf.d/pdo.ini, > /etc/php5/apache2/conf.d/pdo_mysql.ini, > /etc/php5/apache2/conf.d/xdebug.ini
It is not mentioned in the phpinfo() anywhere else.
Php Solutions
Solution 1 - Php
Without actually doing some debugging, I guess you can't be certain that a debugger is working.
But you can be pretty sure -- I guess one should assume that if some aspects of xDebug are working then it would all be working.
Given that, you can confirm that xDebug is installed and in place by trying the following:
-
phpinfo()
-- this will show you all the extensions that are loaded, including xDebug. If it is there, then it's a safe bet that it's working. -
If that isn't good enough for you, you can try using the
var_dump()
function. xDebug modifies the output ofvar_dump()
to include additional information. If this is in place, then xDebug is working. -
xDebug modifies PHP's error output. If your program crashes with xDebug in place, you'll get more information about the failure than with the standard PHP crash output.
-
xDebug also adds a number of helper functions to PHP. You could try any of these to see if it's working. For example, the function
xdebug_get_code_coverage()
should exist and return an array. If it does, then xDebug is installed. If not, it isn't.
Solution 2 - Php
Run
php -m -c
in your terminal, and then look for [Zend Modules]
. It should be somewhere there if it is loaded!
NB
If you're using Ubuntu, it may not show up here because you need to add the xdebug
settings from /etc/php5/apache2/php.ini
into /etc/php5/cli/php.ini
.
My Xdebug settings:
For Xdebug 3 (and above)
[xdebug]
zend_extension = /usr/lib/php5/20121212/xdebug.so
xdebug.mode=debug
xdebug.client_host=localhost
;# The default is 9003
xdebug.client_port=9000
For Xdebug 2.9 (or below)
[xdebug]
zend_extension = /usr/lib/php5/20121212/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
Solution 3 - Php
Try as following, will return xDebug does exists.
or xDebug doesn't exists.
:
<?=sprintf('xDebug does%s exists.', extension_loaded('xdebug') ? '' : "n't");
On CLI:
php -r "printf('xDebug does%s exists.' . PHP_EOL,
extension_loaded('xdebug') ? '' : 'n\'t');"
Solution 4 - Php
After a bitter almost 24 hours long run trying to make xdebug to work with Netbeans 8.0.2, I have found a solution that, I hope, will work for all Ubuntu and Ubuntu related stacks.
Problem number 1: PHP and xdebug versions must be compatible
Sometimes, if you're running a Linux setup and apt-get to install xdebug, it won't get you the proper xdebug version. In my case, I had the latest php version but an old xdebug version. That must be due to my current Xubuntu version. Software versions are dependent on repositories, which are dependent on the OS version you are running.
Solution: PHP has a neat extension manager called PECL. Follow the instructions given here to have it up and running. First, as pointed out by a member at the comments, you should install PHP's developer package in order to get PECL to work:
sudo apt-get install php5-dev
Then, using PECL, you'll be able to install the latest stable version of xdebug:
sudo pecl install php5-xdebug
Once you do it, the proper version of xdebug will be installed but not ready to use. After that, you'll need to enable it. I've seen many suggestions on how to do it, but the fact of the matter is that PHP needs some modules to be enabled both to the client and the server, in this case Apache. It seems that the best practice here is to use the built in method of enabling modules, called php5enmod. Usage is described here.
Problem number 2: Enable the module correctly
First, you'll need to go inside the /etc/php5 folder. In there, you'll find 3 folders, apache2, cli, and mods_available. The mods_available folder contains text files with instructions to activate a given module. The name convention is [module].ini. Take a look inside a few of them, see how they are set up.
Now you'll have to create your ini file inside mods_available folder. Create a file named xdebug.ini, and inside the file, paste this:
[xdebug]
zend_extension = /usr/lib/php5/20121212/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
Make sure that the directive [xdebug] is present, exactly like the example above. It is imperative for the module to work. In fact, just copy and paste the whole code, you'll be a happier person that way. :D
Note: the zend_extension path is very important. On this example it is pointing o the current version of the PHP engine, but you should first go to /usr/lib/php5 and make sure the folder that is named with numbers is the correct one. Adjust the name to whatever you see there, and while you're at it, check inside the folder to make sure the xdebug.so is really there. It should be, if you did everything right.
Now, with your xdebug.ini created, it's time to enable the module. To do that, open a console and type:
php5enmod xdebug
If everything went right, PHP created two links to this file, one inside /etc/php5/apache2/conf.d and other inside /etc/php5/cli/conf.d
Restart your Apache server and type this on the console:
php -v
You should get something like this:
PHP 5.5.9-1ubuntu4.6 (cli) (built: Feb 13 2015 19:17:11)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.3.1, Copyright (c) 2002-2015, by Derick Rethans
Which means the PHP client did read your xdebug.ini file and loaded the xdebug.so module. So far so good.
Now create a phpinfo script somewhere on your web server, and run it. This is what you should see, if everything went wright:
If you see this, Apache also loaded the module, and you are probably ready to go. Now let's see if Netbeans will debug correctly. Create a very simple script, add some variables, give them values, and set a break point on them. Now hit CTRL+F5, click on "step in" on your debugger panel, and see if you get something like this:
Remember to check Netbeans configuration for debugging, under tools/options/php. It should look something like this:
I hope this sheds some light on this rather obscure, confusing problem.
Best wishes!
Solution 5 - Php
Just to extend KsaRs answer and provide a possibility to check xdebug from command line:
> php -r "echo (extension_loaded('xdebug') ? '' : 'non '), 'exists';"
Solution 6 - Php
Starting with xdebug 3 you can use the following command line :
php -r "xdebug_info();"
And it will display useful information about your xdebug installation.
Solution 7 - Php
you can run this small php
code
<?php
phpinfo();
?>
Copy the whole output page, paste it in this link. Then analyze. It will show if Xdebug is installed or not. And it will give instructions to complete the installation.
Solution 8 - Php
If you are using Eclipse then please note that while running on XDebug mode the magic constant _FILE_ will always be evaluated to:
xdebug://debug-eval
So the following check will return true if your session is under XDebug:
$is_xdebug = false !== strpos(__FILE__,'xdebug'); // true while on XDebug
Solution 9 - Php
in your question you mentioned that your phpinfo was stating that apache was loading xdebug's configuration in /etc/php5/apache2/conf.d/xdebug.ini In many of the instructions online you may note that they ask you to put xdebug config in php.ini (and that is what I did) HOWEVER, if the configuration is set to /etc/php5/apache2/conf.d/xdebug.ini, then you should remove the [XDebug] configuration settings from /etc/php5/apache2/php.ini and put it in /etc/php5/apache2/conf.d/xdebug.ini INSTEAD. Once I removed from /etc/php5/apache2/php.ini and put in /etc/php5/apache2/conf.d/xdebug.ini instead, and restarted apache, it worked!!
Therefore, in your /etc/php5/apache2/conf.d/xdebug.ini, put the following:
[XDebug]
zend_extension="/usr/lib/php5/20121212+lfs/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port="9000"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/home/paul/tmp"
xdebug.remote_host="localhost"
xdebug.remote_handler="dbgp";
xdebug.idekey="phpstorm_xdebug"
then remove this from the /etc/php5/apache2/php.ini if you put it there as well.
Then do:
sudo service apache2 restart
Then it should work!!!
Solution 10 - Php
Solution 11 - Php
Be aware that with xDebug 3 the configuration options have changed. The PhpStorm Manual: Configure xDebug also explains it well (it comes with a validator script, which is being uploaded). After messing around with a PECL version, which could not be configured, the answer was:
su
dnf remove php-xdebug
dnf install php-devel
cd /usr/src
wget https://xdebug.org/files/xdebug-3.0.4.tgz
tar -xvzf xdebug-3.0.4.tgz
cd xdebug-3.0.4/
phpize
./configure --enable-xdebug
make
make install
xDebug 3 works with such a config (notice the [xdebug]
section):
; Enable xdebug extension module
zend_extension=xdebug.so
[xdebug]
xdebug.mode=debug
xdebug.client_host=localhost
xdebug.client_port=9003
Which goes into these two files:
nano /etc/php-cli.d/xdebug.ini
nano /etc/php.d/xdebug.ini
Then one can permit the network connection and reload the INI:
setsebool -P httpd_can_network_connect 1
systemctl restart php-fpm.service
And finally:
php -r "xdebug_info();"
Solution 12 - Php
I realize this question is a bit old, but xdebug 3 came out and a lot of things have changed.
php.exe -r "xdebug_info();"
Still works, but the configuration in php.ini is different:
For a xampp installation (php 8.0.12) I have:
[xdebug]
zend_extension="C:\xampp\php\zend_ext\php_xdebug-3.1.1-8.0-vs16-x86_64.dll"
xdebug.output_dir="c:/xampp/xdebug"
xdebug.mode=debug
xdebug.log=c:/xampp/xdebug/xdebug.log
xdebug.log_level=7
xdebug.profiler_output_name=%p.%t.cgrind
Which also will write a xdebug.log
file with the following content:
[8028] Log opened at 2021-10-28 09:42:33.878279
[8028] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[8028] [Config] INFO: No shared secret: Activating
[8028] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[8028] [Step Debug] ERR: Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
[8028] Log closed at 2021-10-28 09:42:34.298475
For wampserver xdebug is included and active out of the box. Which makes it a bit easier to work with.