56

I am trying to debug some PHP code and wanted to download the XDebug debugger for PHP. All I see there is Windows binaries for downloading. Is it at all possible to use it on Ubuntu?

Undo
  • 25,519
  • 37
  • 106
  • 129
Genadinik
  • 18,153
  • 63
  • 185
  • 284

7 Answers7

113

Execute the following commands in your terminal.

Download Xdebug - you will need to follow alternate instructions if you don't have PHP5 working on your machine already.

sudo apt-get install php5-xdebug

The package should modify your INI file for you, but just in case you need to edit it yourself open it up and make the following modification - on Ubuntu its typically at /etc/php5/apache2/php.ini - add the following line.

zend_extension="/usr/lib/php5/20110331/xdebug.so"

That path might be a little different on your system - just make sure its a fully qualified path to the xdebug.so file on your machine. Also remember to comment out any references to the Zend Debugger - you can't run both at the same time.

Now restart Apache.

sudo /etc/init.d/apache2 restart

You may also need want enable html_errors. Search for html_errors in /etc/php5/apache2/php.ini and make sure it is set to On. A restart of Apache is also required.

html_errors = On

Double-check with phpinfo() to make sure that everything is installed properly - you may also want to set configurations for Xdebug in your php.ini file.

Community
  • 1
  • 1
Jarrod Nettles
  • 6,193
  • 6
  • 28
  • 46
  • 11
    1) You don't need to install php5-dev nor php-pear for XDebug in Ubuntu (only if you want to compile it yourself). 2) Even if you had to, apt would take care of it automatically. 3) dpkg will also create the `/etc/php5/conf.d/xdebug.ini` file for you. In short, all you need to do is to install php5-xdebug and restart Apache, period. – netcoder Mar 31 '11 at 18:22
  • @netcoder Do you know what is the right spot to place the line zend_extension="/usr/lib/php5/20110331/xdebug.so" within the php.ini file? - Thanks :) – Genadinik Mar 31 '11 at 18:39
  • 2
    @Genadinik: Like I said, `apt` does it for you. You don't have to worry about it. – netcoder Mar 31 '11 at 18:43
  • @Genadinik Any place in php.ini will do fine, if it hasn't already modified your INI for your, like netcoder says that it will. I typically group extensions that I add at the bottom of the ini so I know where they all are. – Jarrod Nettles Mar 31 '11 at 19:50
  • @netcoder - Modified the answer to reflect your comment. I was unaware it modded the INI file for you! Learn something new every day. – Jarrod Nettles Mar 31 '11 at 19:53
  • 1
    html_errors = On this part is needed in ubuntu to get a nice output. Thx – Gianpaolo Di Nino May 28 '13 at 10:07
  • is installation of xdebug depend upon version of ubuntu ( 13.10[ 64 bit] )? http://askubuntu.com/questions/395635/install-xdebug-error – Ravinder Kumar Dec 30 '13 at 11:09
  • 1
    If you use Netbeans, maybe you need to add the lines in the answer http://stackoverflow.com/questions/2963027/netbeans-xdebug-php-not-working to make it work. This is cool to install it, but I couldn't make it work until I added the lines – Federico J. Apr 19 '14 at 15:58
  • `sudo apt-get install php5-xdebug` in ubuntu its says . E: Unable to locate package php5-xdebug – dipenparmar12 Apr 20 '20 at 12:50
20
sudo apt-get install php5-xdebug
Darren
  • 13,050
  • 4
  • 41
  • 79
Parris Varney
  • 11,320
  • 12
  • 47
  • 76
13

On a newer Ubuntu (at least on 14.04 LTS), I needed to activate the module as well. So, in total I did:

sudo apt-get install php5-xdebug
sudo php5enmod xdebug

After a restart of the server, xdebug was available.

kronn
  • 925
  • 11
  • 31
13

This article was what helped me in Ubuntu 16.04 running PHP7:
Link to article

sudo apt-get install php-xdebug
CIRCLE
  • 4,501
  • 5
  • 37
  • 56
  • I've just tried above every single commands, without any solution. Then finally your comment helped me out! Works on Ubuntu 14.04 as well. Thanks! – Bálint Pap Jan 08 '17 at 17:18
3

::ubuntu 18.04, php7.2, apache2:: 1. First install xdebug using sudo apt-get install php-xdebug. 2. This will create file /etc/php/7.2/mods-available/xdebug.ini 3. You can run sudo phpenmod xdebug 4. open xdebug.ini using sudo nano /etc/php/7.2/mods-available/xdebug.ini 5. you can see only the line: zend_extension=xdebug.so 6. assuming running php apache on localhost and netbeans IDE, add following line to xdebug.ini

xdebug.show_error_trace = 1
xdebug.idekey=netbeans-xdebug
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1

N.B: xdebug.idekey and xdebug.remote_port can be obtained from netbeans tools->optins->php->debug

0

Proper way to install XDEBUG for newest version of LAMPP:

  1. Download: XDEBUG latest version called source.

  2. Extract file to any folder.

  3. Open this folder with terminal.

  4. Change X.X.X to Your actually version of php

  5. Execute the following commands in your terminal.

    /opt/lampp/bin/phpize-X.X.X
    ./configure --with-php-config=/opt/lampp/bin/php-config-X.X.X
    make
    cp modules/xdebug.so /opt/lampp/lib/php/extensions/no-debug-non-zts-20170718
    

Now we need edit file php.ini

  1. Open folder where is file php.ini in terminal:

    sudo nano ./php.ini
    
  2. Add to the end of file this:

    zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
    
  3. Open LAMPP folder in terminal

  4. Now restart Apache.

    sudo ./xampp restart
    

And now You can check phpinfo() to see XDEBUG is installed.

MESSIAH
  • 1
  • 6
-1

Try compiling from source, that's what I do on my mac.

Otherwise, this might help you: http://ubuntuforums.org/showthread.php?t=525257

bl00dshooter
  • 991
  • 2
  • 10
  • 17