36

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 ?

7 Answers 7

59

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/7.0/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
2
  • 1
    The OP already is installing it using apt. You answer don't solve the problem. Nov 3, 2018 at 23:16
  • 1
    for php8.0 xdebug, sudo nano /etc/php/8.0/mods-available/xdebug.ini 1st line is: zend_extension=/usr/lib/php/20200930/xdebug.so
    – Aipo
    Sep 15, 2021 at 6:46
12

I use the following method and it works retrieve content from php info

$ php -i> info.txt

copy all the text in the info.txt file then enter the xdebug installation wizard and follow the ranks available there.

will look like this

Download xdebug-2.7.2.tgz
Install the pre-requisites for compiling PHP extensions.
On your Ubuntu system, install them with: apt-get install php-dev autoconf automake
Unpack the downloaded file with tar -xvzf xdebug-2.7.2.tgz
Run: cd xdebug-2.7.2
Run: phpize (See the FAQ if you don't have phpize).

As part of its output it should show:

Configuring for:
...
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.

Run: ./configure
Run: make
Run: cp modules/xdebug.so /usr/lib/php/20170718
Update /etc/php/7.2/cli/php.ini and change the line
zend_extension = /usr/lib/php/20170718/xdebug.so
3
  • that wizard is really helpful! Dec 10, 2019 at 16:26
  • Dont know how many times I've been installing xdebug, but first time I see this. Seems very helpful!
    – jgangso
    Aug 14, 2020 at 10:18
  • You need to run phpize for the required PHP version as in xdebug.org/docs/faq#api Aug 22, 2021 at 16:17
7

How to install Xdebug on Ubuntu

If none of the above solutions worked for you, then your last resort might be to use pecl

If you don't have pecl installed already:

sudo apt -y install php7.3-dev php-pear // replace php7.3 with your version

Run pecl to install xdebug:

sudo pecl install xdebug

At the end of the installation, you may see this output:

Build process completed successfully
Installing '/usr/lib/php/20180731/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.0.2
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib/php/20180731/xdebug.so" to php.ini

Open your php.ini file, add the zend_exntension line at the very bottom (skip if pecl was able to place it already):

sudo vim /etc/php/7.3/apache2/php.ini // again replace 7.3 with your version

Finally, restart your webserver, or PHP-FPM, depending on what you are using.

2
  • 1
    Thanks. Solved my issue ton install xdebug for php7.4 on Ubuntu 18.04 Feb 22, 2022 at 14:47
  • 1
    Working for Ubuntu 20.04 and PHP 7.2
    – Manuel
    Jul 7, 2022 at 15:03
6

I think that you should update the local package index with the latest changes made in the repositories first by typing the following command :

sudo apt update

Or

sudo apt-get update

The APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file and in the /etc/apt/sources.list.d directory.

Credits

2

For anyone finding this answer, please bear in mind that there are significant changes between xdebug 2 and xdebug 3. There is upgrade guide provided by XDebug here: http://xdebug.org/docs/upgrade_guide

1

Update for php 7.4.8: In the Xdebug configuration file

/etc/php/7.4/mods-available/xdebug.ini

I had to add the line:

xdebug.force_display_errors = 1

As Xdebug wouldn't work instead.

0

please, disable ppa/php and run sudo apt install php-xdebug

1
  • Removing ppa/php is certainly not what he wants... There are other alternatives (see others answers). Feb 22, 2022 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.