简介
Xdebug 是一个开源的PHP程序调试器;可以帮助你跟踪、调试和分析PHP程序,也可以帮你了解PHP底层的实现原理和结构。
Windows 安装
1. 下载
去官网下载 下载地址。
Warning: PHP版本不同对应的xdebug扩展也不一样,如果不知道选哪个可以看这里。
注意下载页面有个 custom installation instructions. 点击这个会跳转到一个新的页面
按照上面给的提示有两种方法可以知道当前适合哪种xdebug扩展(这里使用第二种方法):
输入框里贴入 <?php echo phpinfo(); ?> html代码
使用 php -i 方法。
打开 cmd 输入 php -i 命令回车。(这里面需要注意php是否加入系统环境变量,如果没有需要进入php安装目录)
点击按钮 Analyse my phpinfo() output,然后会推荐你下载某个版本的xdebug扩展,这个功能可以帮我们省了很多时间。
2. 配置
下载好将 php_xdebug-2.7.2-7.2-vc15-x86_64.dll 扩展放在 ext 目录下。
然后打开 php.ini 添加下面内容
; XDEBUG Extension
[xdebug]
zend_extension ="D:/wamp64/bin/php/php5.6.40/zend_ext/php_xdebug-2.5.5-5.6-vc11-x86_64.dll"
xdebug.idekey="PHPSTORM"
xdebug.remote_enable = on
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="D:/wamp64/tmp"
xdebug.show_local_vars=0
xdebug.remote_handler = dbgp
; 设置xdebug的端口为9001, 要和编辑器设置的一致哦
xdebug.remote_port = "9001"
Centos 7 安装
1. 下载。
官网下载,选择对应版本的source 压缩文件,下载好后将压缩包上传到服务器上
在服务器上使用 wget http://www.xdebug.org/files/xdebug-2.7.2.tgz 命令,获取xdebug扩展压缩包
2. 解压
tar zxvf xdebug-2.7.2.tgz,解压后进入文件夹 xdebug-2.7.2,
3. 源码编译安装
phpize 创建configure 文件,如果提示没有这个文件,可以使用 find / -name phpize 找到这个文件的绝对路径。
运行./configure,如果需要手动指定PHP的配置路径,运行./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
编译安装 make && make install
修改配置文件 php.ini 添加
[xdebug]
;注意路径要写对
zend_extension="/path/php/ext/xdebug.so"
重启php systemctl restart php-fpm
测试
使用 echo phpinfo() 输出可以看到php安装xdebug已经成功;
参考