运行环境:
系统:macOS
环境:xampp(php:5.6)
IDE:phpstorm 2016.2
<h1>一、安装Xdebug</h1>
<ol><li>假定我们已经安装好了<a href="https://www.apachefriends.org/download.html">xampp</a>,mac系统自带了php,但这里我们使用的是xampp下的php,在这里为了操作方便,我们把它的环境变量设为全局,方便操作,先打开finder

<a>/Applications/XAMPP/bin</a>
<a>/Applications/XAMPP/xamppfiles/bin</a>
点击保存,退出。</li><li>获取phpinfo信息,有两种方法:
1)新建一个test.php文件(),内容如下:
<code>
<?php phpinfo();?>
</code>
保存,退出;
打开terminal,然后执行这个脚本:


2)打开terminal,运行<code>php -i</code>命令,复制输出的信息;</li><li>打开<a>https://xdebug.org/wizard.php</a>,把复制的信息粘贴进文本框

点击下方的“Analyse my phpinfo() output”按钮,弹出新网页,会显示如下信息(环境下对应版本的xdebug、安装的方法以及可能出现的问题的解决方法):

点击download下载,解压,把文件夹复制到php的扩展文件里:
<a>/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226</a>
打开终端,运行<code>cd /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/xdebug-2.5.0rc1</code>,
然后运行
<code>
phpize
./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
sudo make
sudo make install
</code>
即可。
(详情请参考http://doc.okbase.net/myall/archive/177709.html)
此时,目录里应该会有“xdebug.so”文件,到此我们已经安装好了xdebug扩展</li></ol>
<h1>二、配置环境</h1>
<ol><li>配置php.ini文件(地址:/Applications/XAMPP/xamppfiles/etc/php.ini),配置如下:
<code>
zend_extension = "/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so"
xdebug.remote_autostart=On
xdebug.remote_enable=On
xdebug.remote_mode="req"
xdebug.remote_host="localhost" //或者127.0.0.1
xdebug.remote_port=9999 //默认是9000,选9999避免可能和php-fpm冲突
xdebug.remote_handler="dbgp"
xdebug.idekey="PHPSTORM"
xdebug.max_nesting_level=600</code>
保存,需要重启服务器令配置生效</li><li>配置phpstorm:
1)配置PHP,如下图:


2)配置Xdebug
点击工具栏选preferences》PHP》Debug,配置如下图:

点击工具栏选preferences》PHP》Debug》DBGp Proxy,配置如下图:

IDEKey需要与php.ini配置中xdebug.idekey项一致;
Host填localhost;
Port根据个人选择,一般与Apache的http.conf配置中监听端口listen一致,为80端口即可;
3)配置Severs:

4)配置Configurations,如下图:
选择Edit Configurations

添加PHP Web Applicaiton,填写好Server还有Start URL信息


</li>
</ol>
<h1>三、运行,调试</h1>
<ol><li>如下图,点击开始监听,在所需要的地方设置断点:

</li><li>我在这里比较常用的是两种方式,
一种是浏览器,输入网址请求即可,需要配合插件xdebug helper使用,设置选项如下图:

然后开启调试模式:

还有一种是使用Chrome的postman插件进行调试,我们在请求的地址后面输入参数如下图:

</li><li>然后phpstorm会自动弹出到我们设置的断点处(目前我使用Yii2框架,一直都会先在index.php入口脚本处中止一次),显示结果如下图:

</li>
</ol>
<h6>至此,手把手教mac系统xampp环境下给phpstorm安装Xdebug并进行调试的教程完成。</h6>
网友评论