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

StackOverflow https://stackoverflow.com/questions/23408771

문제

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?

도움이 되었습니까?

해결책

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 

다른 팁

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).

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

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.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top