Is it possible to use xdebug on Ubuntu?

2019-01-21 02:08发布

问题:

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?

回答1:

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.



回答2:

sudo apt-get install php5-xdebug


回答3:

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.



回答4:

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

sudo apt-get install php-xdebug


回答5:

::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



回答6:

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.



回答7:

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

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