Xdebug Error: "Failed loading xdebug.so: xdebug.so: cannot open shared object file: No such file or directory"

46,166

Solution 1

Even though you have the two sites split up and using two different php.ini files, CRON will still use whichever php.ini file the PHP-CLI is configured to use. So, to figure out which php.ini CRON is using, this is the command to use:

php -i | grep php.ini

If PHP-CLI happens to be using a php.ini file that you didn't expect it to be using (such as /usr/local/lib/php.ini) then that will be the key to figuring out why you're seeing Xdebug errors in the logs.

It turns out that the /usr/local/lib/php.ini file had these two values set:

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20090626"
zend_extension = "xdebug.so"

That was causing the error from the php script that was run by CRON (i.e. PHP-CLI) because zend_extensions need the full path to the module. This is also stated in the Xdebug documentation: http://xdebug.org/docs/install

So, to get rid of the error, just comment out that line (or just remove it). You could also comment out or remove the extension_dir line as long as you are not loading any other modules such as:

extension = memcached.so 

Solution 2

Sometimes might be difficult from where the XDebug library is loaded since it can be done either by specifying the path in php.ini or by adding the lib in mods-available.

Firstly, run:

$ sudo grep 'xdebug' -r /etc/php/*

This will give you the files that loads the extension.

Now identify which php.ini is in use:

$ php -i | grep php.ini

This will give you the php version in use (in case you have multiple php versions). Now link the php version with the result from the first step.

Now, either you have to comment out the line where the xdebug extension is loaded or remove the xdebug.ini file (that loads the extension) from /etc/php/x.x/mods-available (where x.x stands for the php version in use).

Solution 3

I tried all the processes mentioned above and for this and many similar after Googling around, I still ended up with this error

$  php -i | grep php.ini
Failed loading /usr/lib/php/20200930/xdebug.so:  /usr/lib/php/20200930/xdebug.so: undefined symbol: zend_get_properties_for
Configuration File (php.ini) Path => /etc/php/7.3/cli
Loaded Configuration File => /etc/php/7.3/cli/php.ini

I resolved this by Updating Xdebug using Pecl. If you do not have it installed following the instruction here

$ pecl install xdebug

Now I changed my xdebug.ini file. You can use

$ locate xdebug.ini

Add zend_extension = usr/lib/php/20180731/xdebug.so to the file.

xdebug.ini

[xdebug]
zend_extension = usr/lib/php/20180731/xdebug.so

The latest version of Xdebug 3.0.4 still uses these usr/lib/php/20180731/xdebug.so but if you try to use $ locate xdebug.so you would see a different file location.

Php output the right Zend Extensions

$ php -v
PHP 7.3.27-9+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Feb 23 2021 15:10:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.27-9+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

Solution 4

For the record, in Linux Mint and I think in some Ubuntu Systems. To change the php.ini it's the best to go to /etc/php/7.0/cli/conf.d and look for the xdebug.ini and you must change the lines said in the post above mine.

Solution 5

I tried below in Linux and worked,

you can use the below command to locate the xdebug.so file path

locate xdebug.so

ex: /usr/lib/php/20160303/xdebug.so

use below command to locate the current php.ini file

php -i | grep php.ini

ex: 

Configuration File (php.ini) Path => /etc/php/7.1/cli
Loaded Configuration File => /etc/php/7.1/cli/php.ini

After that add below xdebug configuration to both cli and apache2 folder's php.ini files with correct xdebug.so file path.

vi /etc/php/7.1/cli/php.ini
vi /etc/php/7.1/apache2/php.ini

[xdebug]
zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_autostart = 1

Finally, restart the apache2 server

sudo service apache2 restart

Make sure that you are using the correct xdebug port in your editor!

Cheers! :)

Share:
46,166

Related videos on Youtube

Brett
Author by

Brett

Updated on May 17, 2021

Comments

  • Brett
    Brett almost 3 years

    I recently installed xdebug on my server but restricted it's use to our test site, which uses it's own php.ini file.

    For example, the test sites php.ini is located at:

    /home/test_site/public_html/subdomain_name/php.ini
    

    Inside this php.ini file I have the below for xdebug:

    [XDebug]
    zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
    
    xdebug.profiler_append = 0
    
    xdebug.profiler_enable = 1
    
    xdebug.profiler_enable_trigger = 0
    
    xdebug.profiler_output_dir = /home/test_site/xdebug
    
    xdebug.profiler_output_name = "cachegrind.out.%s-%u.%h_%r"
    

    Now, the thing is, xdebug works fine, no problems.

    However, on our main site, which also has it's own php.ini file, which is located for example at:

    /home/main_site/public_html/php.ini
    

    Inside this file I have nothing for xdebug in there.

    Now, I recently setup a cron in cpanel for the main site such as:

    php -f /home/main_site/public_html/cron_jobs/main_cron.php > /home/main_site/public_html/logs/main_cron.log 2>&1
    

    Now, upon checking the output of the cron inside the log file I get the output:

    Failed loading xdebug.so:  xdebug.so: cannot open shared object file: No such file or directory
    

    Why am I getting this error when the main site shouldn't even be loading xdebug?

    • dcarrith
      dcarrith about 10 years
      You might need to double check that the php-cli version that you're using to run the main_cron.php script isn't using the php.ini that has the xdebug configurations in it. php -i | grep xdebug should show you. Then, php -i | grep php.ini should show you which php.ini the php-cli is configured to use.
    • Abed Hawa
      Abed Hawa about 10 years
      Please try which php to figure out the path of PHP version which is executing your script.
    • Brett
      Brett about 10 years
      @dcarrith When I ran php -i | grep xdebug I got Failed loading xdebug.so: xdebug.so: cannot open shared object file: No such file or directory. When I ran php -i | grep php.ini I got the same error message as well as Configuration File (php.ini) Path => /usr/local/lib ... Loaded Configuration File => /usr/local/lib/php.ini
    • Brett
      Brett about 10 years
      @KraneBird /usr/local/bin/php
    • dcarrith
      dcarrith about 10 years
      @Brett - Have you checked the /usr/local/lib/php.ini to see if there is a zend_extension=xdebug.so in there somewhere? You may just have to set the extension_dir to wherever xdebug.so is stored. sudo find / -name xdebug.so to find it. Then, restart Apache of course.
    • dcarrith
      dcarrith about 10 years
      The important thing to take away from this is, CRON uses php-cli. It looks like your php-cli is configured to use /usr/local/lib/php.ini as the configuration file. I'm not sure why xdebug works for one site and not the other though. This is at least a hint as to what might be happening.
    • Brett
      Brett about 10 years
      @dcarrith I will check that out - but what I'm wondering is, why is it even looking for xdebug?
    • Brett
      Brett about 10 years
      @dcarrith Ok, I checked and have these lines: extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20090626" and zend_extension="xdebug.so"; I searched for the correct path and it gave the same path that I use for xdebug that I have in the php.ini file that is on the site I am using it on where it is working.
    • Brett
      Brett about 10 years
      @dcarrith I assume I can just comment out the zend_extension="xdebug.so" in that file?
    • dcarrith
      dcarrith about 10 years
      @Brett - I was wrong when I said you might just have to set extension_dir since Xdebug needs the full path. So, I would try two things to see what happens. Try commenting it out to see if it breaks it on the site you want it working. Then, try giving it an absolute path to see if it will at least get rid of the error. zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20090626/xdeb‌​ug.so
    • dcarrith
      dcarrith about 10 years
      See the docs where they put "full path" in bold print: xdebug.org/docs/install
    • Brett
      Brett about 10 years
      @dcarrith Commenting it out worked - Error message is now gone and xdebug still works on that one site. :) Feel free to add your solution as an answer and you will get the bounty. :)