Check if xdebug is working

Without installing a text editor or IDE, you can check if xdebug works, i.e. if it can debug php code?

The only part of xdebug appears in phpinfo ():

Additional .ini files are analyzed / etc / php 5 / apache2 / conf.d / mysql.ini, / etc / php 5 / apache2 / conf.d / mysqli.ini, / etc / php5 / apache2 / conf.d / pdo. ini, / etc / php 5 / apache2 / conf.d / pdo_mysql.ini, / etc / php 5 / apache2 / conf.d / xdebug.ini

It is not mentioned in phpinfo () anywhere else.

+64
php xdebug
Dec 26
source share
9 answers

Without doing some debugging, I think you cannot be sure that the debugger is working.

But you can be very sure - I think it should be assumed that if some aspects of xDebug work, then everything will work.

Given this, you can confirm that xDebug is installed and in place by trying the following:

1) phpinfo() - this will show you all downloadable extensions, including xDebug. If it is, then it is a safe bet that it works.

2) If this is not enough for you, you can try using the var_dump() function. xDebug modifies the output of var_dump() to include additional information. If it is in place, then xDebug works.

3) xDebug changes the output of a PHP error. If your program crashes with xDebug, you will get more information about the crash than with the standard PHP crash output.

4) xDebug also adds a number of helper functions for PHP. You can try any of them to see if it works. For example, the xdebug_get_code_coverage() function must exist and return an array. If so, then xDebug is installed. If not, it is not.

+72
Dec 26
source share

Run

 php -m -c 

in your terminal, and then find [Zend Modules] . It must be there somewhere if it is loaded!

NB

If you use Ubuntu, it may not appear here because you need to add the xdebug settings from /etc/php5/apache2/php.ini to /etc/php5/cli/php.ini . Mines

 [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 
+50
Mar 27 '14 at 20:10
source share

Try the following: Return or Does Not Exist:

 <?php echo (extension_loaded('xdebug') ? '' : 'non '), 'exists'; 
+22
01 Oct '15 at 22:59
source share

After a bitter almost 24-hour run trying to get xdebug to work with Netbeans 8.0.2, I 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 use Linux installation and apt-get to install xdebug, it will not give you the correct version of xdebug. In my case, I had the latest version of php, but the old version is xdebug. This should be related to my current version of Xubuntu. The software version depends on the repositories, which depend on the OS version that you are using.

PHP has a neat extension manager called PECL. Follow the instructions here to launch it. First, as a member noted in the comments, you must install the PHP developer package to get PECL to work:

 sudo apt-get install php5-dev 

Then, using PECL, you can install the latest stable version of xdebug:

 sudo pecl install php5-xdebug 

Once you do this, the correct version of xdebug will be installed, but not ready for use. After that you need to enable it. I have seen many suggestions on how to do this, but the fact is that PHP needs some modules that will be included both for the client and the server, in this case Apache. It seems that the best way is to use the built-in module inclusion method called php5enmod. Use is described here .

Problem number 2: enable the module correctly

First you need to enter the / etc / php 5 folder. There you will find 3 folders, apache2, cli and mods_available. The mods_available folder contains text files with instructions for activating this module. The naming convention is [module] .ini. Look at a few of them, see how they are configured.

Now you need to create your ini file inside the mods_available folder. Create a file called 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 [xdebug] directive exists, as in the example above. Be sure the module works. In fact, just copy and paste the whole code, you will become a happier person .: D

Note: the zend_extension path is very important. In this example, this points to the current version of the PHP engine, but first you have to go to / usr / lib / php 5 and make sure that the folder with the name with the numbers is correct. Set the name to what you see there, and while you are on it, check inside the folder to make sure xdebug.so is really there. This should be if you did everything right.

Now that your xdebug.ini has been created, it's time to turn on the module. To do this, open the console and enter:

 php5enmod xdebug 

If everything went right, PHP created two links to this file: one inside / etc / php 5 / apache2 / conf.d and the other inside / etc / php 5 / cli / conf.d

Restart the Apache server and enter it into 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 

This means that the PHP client 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 goes against:

enter image description here

If you see this, Apache also loaded the module, and you are probably ready to go. Now let's see if Netbeans is debugging properly. Create a very simple script, add some variables, give them values ​​and set a breakpoint for them. Now press CTRL + F5, click "step in" in the debugger panel and see if you have something like this:

xdebug in action

Remember to check the Netbeans configuration for debugging under tools / options / php. It should look something like this:

Debugging configurations on Netbeans

I hope this sheds some light on this rather obscure, confusing problem.

Regards!

+19
Mar 08 '15 at 12:40
source share

you can run this little php code

 <?php phpinfo(); ?> 

Copy the entire output page, paste it into the link. Then analyze. It will show if Xdebug is installed or not. And he will give instructions to complete the installation.

+4
Jun 30 '17 at 9:43 on
source share

If you use Eclipse , then note that when working in XDebug mode, the magic constant __FILE__ will always be evaluated using:

 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 
+2
May 17 '15 at
source share

in your question you mentioned that your phpinfo stated that apache downloaded the xdebug configuration to / etc / php 5 / apache2 / conf.d / xdebug.ini In many instructions on the Internet you may notice that they ask you to install xdebug config in php .ini (and this is what I did) HOWEVER if the configuration is set to / etc / php 5 / apache2 / conf.d / xdebug. ini, then you must remove the [XDebug] configuration settings from / etc / php 5 / apache2 / php.ini and put it in / etc / php 5 / apache2 / conf.d / xdebug.ini INSTEAD. As soon as I removed from / etc / php 5 / apache2 / php.ini and placed it in / etc / php 5 / apache2 / conf.d / xdebug.ini and restarted apache, it works !!

Therefore, in your / etc / php 5 / 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 / etc / php 5 / apache2 / php.ini if ​​you put it there.

Then do:

sudo service apache2 restart

Then it should work !!!

+1
Feb 13 '15 at 6:10
source share

Just to extend KsaR's answer and provide the ability to check xdebug from the command line:

 php -r "echo (extension_loaded('xdebug') ? '' : 'non '), 'exists';" 
0
Nov 08 '18 at 13:49
source share

I found this the easiest solution - https://xdebug.org/wizard.php

0
Jan 25 '19 at 19:08
source share



All Articles