初学PHP(5.6),一直苦于无法进行debug操作,通过打印日志的方式来查看debug信息,总感觉不是很直接、方便。
今天通过摆渡和骨骼算是找到了比较完美的解决方案,先记录在此,后续如有更好的方法,再进行更新。
1.安装xdebug
在终端查看是否已经安装xdebug,执行操作:brew search xdebug
查看是否已经安装对应版本的xdebug,如果没有则执行安装操作
brew install homebrew/php/php56-xdebug
2.配置xdebug
使用php内置服务器启动服务:php -S 0.0.0.0:8080
查看phpinfo(),Additional .ini files parsed 配置项中包含 /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini,打开该文件,添加
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
3.配置PhpStorm
Preferences…
Debug port设置成9000
操作完成,基于Built-in HTTP server用PhpStorm打开启动的项目,执行PhpStorm菜单Run->Start Listening for PHP debug Connections。请求对应的文件,即可在PhpStorm中设置断点,进行对应的debug操作。