phpxdebug

How to install Xdebug on Ubuntu?


I'm trying to install xdebug on Ubuntu:

sudo apt-get install php-xdebug

and getting following error:

Need to get 806 kB of archives. After this operation, 4.423 kB of additional disk space will be used. Err:1 http://ppa.launchpad.net/ondrej/php/ubuntu artful/main amd64 php-xdebug amd64 2.5.5-3+ubuntu17.10.1+deb.sury.org+1 404 Not Found E: Failed to fetch http://ppa.launchpad.net/ondrej/php/ubuntu/pool/main/x/xdebug/php-xdebug_2.5.5-3+ubuntu17.10.1+deb.sury.org+1_amd64.deb 404 Not Found E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

How can I solve this problem ?


Solution

  • First, you need to update local packages using the following command:

    sudo apt update
    # OR
    sudo apt-get update
    

    Now you can install xdebug with the following command:

    sudo apt install php-xdebug
    

    And configure it as:

    sudo nano /etc/php/{YOUR_PHP_VERSION}/mods-available/xdebug.ini
    

    Add the following code into it:

    zend_extension=/usr/lib/php/20151012/xdebug.so
    xdebug.remote_autostart = 1
    xdebug.remote_enable = 1
    xdebug.remote_handler = dbgp
    xdebug.remote_host = 127.0.0.1
    xdebug.remote_log = /tmp/xdebug_remote.log
    xdebug.remote_mode = req
    xdebug.remote_port = 9005 #if you want to change the port you can change 
    

    Note: Directory 20151012 is most likely to be different for you. cd into /usr/lib/php and check which directory in this format has the xdebug.so file inside it and use that path.

    And then restart the services:

    sudo systemctl restart php7.0-fpm
    sudo systemctl restart nginx # If you are using nginx server
    sudo systemctl restart apache2 # If you are using apache server
    

    UPDATE 2024/01/11: In Xdebug3 you have to set the following xdebug.ini

    zend_extension=xdebug.so
    xdebug.start_with_request = yes
    xdebug.mode = debug
    xdebug.remote_handler = dbgp
    xdebug.client_host = 127.0.0.1
    xdebug.log = /tmp/xdebug_remote.log
    xdebug.client_port = 9005 #if you want to change the port you can change