php Xdebug 错误:“加载 xdebug.so 失败:xdebug.so:无法打开共享对象文件:没有这样的文件或目录”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23408771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:42:34  来源:igfitidea点击:

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

phpapachedebuggingxdebugphp-ini

提问by Brett

I recently installed xdebugon my server but restricted it's use to our test site, which uses it's own php.inifile.

我最近xdebug在我的服务器上安装了它,但限制它用于我们的测试站点,它使用它自己的php.ini文件。

For example, the test sites php.iniis located at:

例如,测试站点php.ini位于:

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

Inside this php.inifile I have the below for xdebug:

在这个php.ini文件中,我有以下 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 worksfine, no problems.

现在,问题是,xdebug工作正常,没有问题。

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

但是,在我们的主站点上,它也有自己的php.ini文件,例如位于:

/home/main_site/public_html/php.ini

Inside this file I have nothing for xdebugin there.

在这个文件中,我没有任何内容xdebug

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

现在,我最近在 cpanel 中设置了一个 cron,main site例如:

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:

现在,在检查日志文件中的 cron 输出时,我得到了输出:

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?

当主站点甚至不应该加载 xdebug 时,为什么我会收到此错误?

回答by dcarrith

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.ini 文件,CRON 仍将使用 PHP-CLI 配置使用的任何 php.ini 文件。因此,要确定 CRON 正在使用哪个 php.ini,这是要使用的命令:

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.

如果 PHP-CLI 碰巧使用了一个您不希望它使用的 php.ini 文件(例如/usr/local/lib/php.ini),那么这将是找出您在日志中看到 Xdebug 错误的原因的关键。

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

事实证明,该/usr/local/lib/php.ini文件设置了以下两个值:

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

这导致 CRON 运行的 php 脚本(即 PHP-CLI)出现错误,因为 zend_extensions 需要模块的完整路径。这也在 Xdebug 文档中说明: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_dirline as long as you are not loading any other modules such as:

因此,要摆脱错误,只需注释掉该行(或将其删除)。extension_dir只要您不加载任何其他模块,您也可以注释掉或删除该行,例如:

extension = memcached.so 

回答by SimionZ

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.

有时从加载 XDebug 库的位置可能很困难,因为它可以通过在 php.ini 中指定路径或通过在 mods-available 中添加 lib 来完成。

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

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

这将为您提供正在使用的 php 版本(如果您有多个 php 版本)。现在将 php 版本与第一步的结果链接起来。

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

现在,您要么必须注释掉加载 xdebug 扩展名的行,要么从 /etc/php/xx/mods-available(其中 xx 代表正在使用的 php 版本)中删除 xdebug.ini 文件(加载扩展名) )。

回答by antoiba86

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.dand look for the xdebug.ini and you must change the lines said in the post above mine.

作为记录,在 Linux Mint 中,我认为在一些 Ubuntu 系统中。要更改 php.ini,最好转到/etc/php/7.0/cli/conf.d并查找 xdebug.ini,您必须更改我上面帖子中说的行。

回答by Dasitha Abeysinghe

I tried below in Linux and worked,

我在 Linux 中尝试了下面的工作,

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

您可以使用以下命令来定位 xdebug.so 文件路径

locate xdebug.so

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

use below command to locate the current php.ini file

使用下面的命令来定位当前的 php.ini 文件

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.

之后,使用正确的 xdebug.so 文件路径将以下 xdebug 配置添加到 cli 和 apache2 文件夹的 php.ini 文件中。

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

最后重启apache2服务器

sudo service apache2 restart

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

确保您在编辑器中使用正确的 xdebug 端口!

Cheers! :)

干杯! :)