安装 PhpStorm+Xdebug+LNMP 调试环境

前阵子在Mac上安装了LNMP开发环境,这两天在开发调试php程序的时候,发现用echo、printf或var_dump等函数调试程序异常的麻烦,所以就想使用xdebug进行程序调试,网上的很多资料都比较的陈旧,现整理一下集成phpstorm+xdebug的步骤

1. 安装xdebug

由于使用的是Mac进行开发,所以就使用Homewbrew进行软件包的管理

// 安装php版本相对应的xdebug拓展
$  brew install php70-xdebug

2. 配置xdebug

使用brew进行软件包的安装的话,配置文件路径为:/usr/local/etc/php/7.0/conf.d/ext-xdebug.ini

[xdebug]
zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"

;是否开启远程调试自动启动
xdebug.remote_autostart = On

;是否开启远程调试
xdebug.remote_enable = On

;允许调试的客户端IP
xdebug.remote_host=localhost

;远程调试的端口(默认9000)
xdebug.remote_port=9000

;调试插件dbgp
xdebug.remote_handler=dbgp

;是否收集变量
xdebug.collect_vars = On

;是否收集返回值
xdebug.collect_return = On

;是否收集参数
xdebug.collect_params = On

;是否开启调试内容
xdebug.profiler_enable=On

xdebug.idekey = PHPSTORM

配置完之后,由于我使用的是nginx,所以需要重启php-fpm(假如使用的是Apache,则重启Apache服务器)

有两种方式可以检测xdebug是否加载成功

  1. phpinfo()
    xdebug.png

  2. 命令行输入php -m

$  php -m
[PHP Modules]
bcmath
bz2
calendar
...

[Zend Modules]
Xdebug

3. 配置phpstorm

先配置php使用的版本号
phpstorm_1.png

再配置web server
phpstorm_2.png

最后设置phpstorm监听xdebug的端口号,默认为9000
phpstorm_3.png

大功告成:beers:
phpstorm_4.png

本帖已被设为精华帖!
本帖由系统于 7年前 自动加精
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!