如何在Ubuntu 16的PHP 7.2+Apache环境安装Xdebug 2.7及以上版本?
解决Ubuntu 16下PHP7.2安装Xdebug 2.7+的方法
Ubuntu 16.04的官方软件源中Xdebug版本停留在2.4,无法适配PHP7.2,以下是两种可行的安装方法:
方法一:通过PECL安装(推荐,步骤更简洁)
- 先安装编译依赖:
sudo apt-get install php7.2-dev php-pear gcc make autoconf libc-dev pkg-config - 安装指定版本的Xdebug(2.7.2为适配PHP7.2的稳定版):
sudo pecl install xdebug-2.7.2 - 配置PHP加载Xdebug:
- 找到当前PHP的配置文件路径:
php --ini | grep "Loaded Configuration File" - 编辑该配置文件,添加以下内容:
zend_extension=xdebug.so # 可选:添加基础调试配置 xdebug.remote_enable=1 xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000
- 找到当前PHP的配置文件路径:
- 重启Apache使配置生效:
sudo systemctl restart apache2 - 验证安装成功:执行
php -v,输出中应显示Xdebug 2.7.2的版本信息
方法二:手动编译安装(更可控)
- 安装编译依赖:
sudo apt-get install php7.2-dev gcc make autoconf libc-dev pkg-config - 下载Xdebug 2.7.2源码包:
wget https://xdebug.org/files/xdebug-2.7.2.tgz - 解压并进入源码目录:
tar -xzf xdebug-2.7.2.tgz cd xdebug-2.7.2 - 生成编译配置:
phpize - 配置编译选项:
./configure --enable-xdebug - 编译并安装:
make && sudo make install - 重复方法一中的配置PHP、重启Apache、验证步骤即可完成安装
注:你之前执行的
apt-get update xdebug是错误命令,正确的源更新命令为sudo apt-get update,但因Ubuntu16源限制,无法通过apt获取高版本Xdebug,因此需采用上述方法。
内容的提问来源于stack exchange,提问作者Dustin Yoder
相关产品推荐
相关产品推荐

