我们正在尝试在基于Alpine Linux的Docker容器中安装XDebug并运行php-fpm。我们按照本页给出的安装说明进行操作。它说在Alpine Linux中运行下面的命令,我们就是这样做的:
bash-5.0# apk add php7-pecl-xdebug
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/2) Installing php7-common (7.3.22-r0)
(2/2) Installing php7-pecl-xdebug (2.9.1-r0)
OK: 85 MiB in 74 packages
我们可以看到.so
文件位于/usr/lib/php7/modules/xdebug.so
下,因此我们将其添加到/usr/local/etc/php/php.ini
文件中,如下所示:
zend_extension = /usr/lib/php7/modules/xdebug.so
然后重新启动容器。网页上说通过运行
来验证安装:bash-5.0# php -v
当我们运行命令时,我们得到以下输出:
bash-5.0# php -v
Failed loading /usr/lib/php7/modules/xdebug.so: Error relocating /usr/lib/php7/modules/xdebug.so: php_sprintf: symbol not found
PHP 7.4.4 (cli) (built: Mar 24 2020 01:34:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
我们如何解决这个问题?谢谢。如果有帮助的话:
bash-5.0# ls -al /usr/lib/php7/modules/xdebug.so
-rwxr-xr-x 1 root root 268088 Jan 18 2020 /usr/lib/php7/modules/xdebug.so
我认为这个错误来自一些没有安装在系统上的C库。我们根据这个答案执行了以下步骤,并且成功了。它还安装最新版本的xdebug
(版本3.0.2)。apk add php7-pecl-xdebug
正在安装xdebug
的2.9版本。
步骤1:安装依赖项:
apk --no-cache add pcre-dev ${PHPIZE_DEPS}
步骤2:构建二进制文件:
pecl install xdebug
如果成功,应该以
结尾Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20190902/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/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" to php.ini
步骤3:现在编辑php.ini
,并将zend_extension
设置为上面给出的路径
步骤4:验证
bash-5.0# php -v
PHP 7.4.4 (cli) (built: Mar 24 2020 01:34:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies