macOS 下 PHPStorm + Xdebug 调试 Docker 环境中的代码
0x00 描述
宿主机是 mac mini,构建的项目在 docker 中,所以需要在 PHPStorm 上配置 Xdebug 进行远程代码调试。
0x01 环境
宿主机:macOS High Sierra Docker:Docker version -ce, build e68fc7a 容器环境:CentOS Linux release (Core) + PHP + nginx/ + Xdebug PhpStorm:
0x03 下载安装 Xdebug
下载 Xdebug
首先要确定 Xdebug 的版本要和环境中的 PHP 版本相对应。
进入 docker 环境,打印 phpinfo() 的输出页面,或者在命令行输入
php -r "phpinfo();"
得到的结果,全选,复制,把结果粘贴到 https://xdebug.org/wizard.php 的文本框中,查看对应的 Xdebug 版本。
安装Xdebug
把得到的 Xdebug 版本下载到 docker 环境中,按照 https://xdebug.org/wizard.php 的说明进行安装:
Download xdebug-.tgz Unpack the downloaded file with tar -xvzf xdebug-.tgz Run: cd xdebug- Run: phpize (See the FAQ if you don't have phpize. As part of its output it should show: Configuring for: ... Zend Module Api No: Zend Extension Api No: If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step. Run: ./configure Run: make Run: cp modules/xdebug.so /usr/lib64/php/modules Update /etc/php.ini and change the line zend_extension = /usr/lib64/php/modules/xdebug.so
0x04 配置 PHP 与 Xdebug
在 docker 中,根据 phpinfo 的 php.ini 路径,打开 php.ini,加入(编辑)以下代码:
[xdebug] zend_extension=/usr/lib64/php/modules/xdebug.so xdebug.remote_enable= xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=10.203.17.92 xdebug.remote_port= xdebug.idekey=PHPSTORM xdebug.auto_trace= xdebug.auto_exception_trace= xdebug.remote_autostart= xdebug.collect_vars= xdebug.collect_return= xdebug.collect_params= xdebug.show_local_vars= xdebug.profiler_enable= xdebug.trace_enable_trigger= xdebug.remote_log="/var/log/php.xdebug.log"
有几个地方要注意一下:
1. xdebug.remote_host
这是宿主机的 ip,在 docker 外(mac 环境中),输入命令:
ifconfig
找到 en0 中的 inet:
en0: flags=<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV> ether :fe:f7:0a::ff inet6 fe80::4f0:bb3b:4a49:d7f9%en0 prefixlen secured scopeid 0x5 inet 10.203.17.92 netmask 0xffffff00 broadcast 10.203.17.255 nd6 options=<PERFORMNUD,DAD> media: autoselect (100baseTX <full-duplex>) status: active
xdebug.remote_host 就是上面例子中的 10.203.17.92
2. xdebug.remote_port
这里默认是 9000 端口,改一下避免和 php-fpm 的 9000 端口冲突
3. xdebug.remote_log
配置一下,方便排错
另外附上 /etc/php.d/xdebug.ini:
[xdebug] ; repeated defind at /etc/php.d/-xdebug.ini file ; zend_extension=/usr/lib64/php/modules/xdebug.so xdebug.remote_enable = on xdebug.remote_host = 10.203.17.92 xdebug.remote_port = xdebug.idekey = "PHPSTORM"
这里和 php.ini 保持一致。
0x05 配置 PHPStorm
1. 进入 preferences
2. 进入 Languages & Frameworks - PHP -Debug ,找到 Xdebug,编辑监听端口和 php.ini 保持一致。
3. 进入 DBGp Proxy,端口和 php.ini 中配置保持一致,配置如下:
4. 进入 Servers,点 “+” 添加一个测试项目,例子中是 admin,Name 随便填写,Host 写项目的域名,端口 80,Debugger 选 Xdebug,勾选下面的路径映射,在右侧填写与本地项目对应的远程目录
5. 保存。
6. 编辑配置,选择 Edit Configurations
添加一个 PHP Web Page,有的版本是 PHP Web Application,是一样的:
填写配置信息:
Server 选择上两步在 Servers 中添加的 Server,这里是 admin,另外 Start URL 选择项目的首页,即使是 https 的 URL,在上述配置端口的地方一样配置成 80:
7. 保存。
8. 调试:
在代码中设置断点(“1”处),打开“2” 处的电话图标,点击“3”处的 debug 选项,会自动跳到浏览器中之前设置的项目首页,当触发到断点时会自动跳到 PHPStorm 中,“4”处可以跳过断点,“5”处显示变量的值:
0x06 安装浏览器 Xdebug 插件
在 google 商店中找到并安装 Xdebug helper,安装之后可以在任意页面启动调试:
以下是 Xdebug helper 的设置页面:
在一些 https 的项目中,PHPStorm -> Preference -> Languages & Frameworks -> PHP -> Servers 处的端口可以配置成 443,但是这个时候通过 PHPStorm 的 Debug 按钮从 Start Url 处开始无法调试,原因是 Xdebug 会把调试的地址认为是 http://xxxx.com:443 而不是 https://xxxx.com,此时就可以用浏览器的 Xdebug helper 插件来直接 debug,选择下拉菜单中的第一个 Debug 选项就可以开始 debug 了。
macOS 下 PHPStorm + Xdebug 调试 Docker 环境中的代码的更多相关文章
- PHPStorm + Xdebug 调试PHP代码 有大用
星期四, 12/26/2013 - 19:54 - shipingzhong PHPStorm + Xdebug 调试PHP代码 http://e.v-get.com/2013-11-20 16:55 ...
- Linux下用Xdebug调试php
Linux下用Xdebug调试php 博客分类: php PHPLinuxZendEclipseC# 为了调试PHP程序,安装一下xdebug. 官方网址: http://www.xdebug.org ...
- PHP - MAC下PhpStorm安装调试环境xdebug
今天下午一直在捣鼓如何用PhpStorm进行调试,查找了许多资料,零零碎碎的,所以自己弄篇文章记录一下步骤. 安装xdebug 使用brew安装xdebug,语法如下 brew install hom ...
- phpstorm+xdebug调试详细教程
对于PHP开发,初来咋到,开发环境的搭建和理解感觉是最烦人的一件事了.不像JAVA,打开一个Eclipse就可以开搞,Php的Debug都要几个插件来配合工作.这些都是死的,好说.但是对于Xdebug ...
- PHPStorm+XDEBUG 调试Laravel
首先输出phpinfo(); https://xdebug.org/wizard.php 打开然后查看适合你的调试扩展版本 ,目前支持到php7.2 整个页面ctrl+a 复制进去 然后下载 扩展文 ...
- centos7+nginx 1.9.0+php-fpm+phpstorm+xdebug+vmware开发环境搭建
1.php-fpm yum install php-fpm 默认配置在本地9000端口监听 service php-fpm restart启动 2.nginx 1.9.0 需先安装gcc zlib o ...
- PhpStorm+xdebug调试——更新
之前写过一篇<PhpStorm+xdebug+postman调试>,但是经过后来一段时间的使用,发现有些累赘.这里介绍一种比较简单方便的操作. 在上一篇文章中有一段“ 7.设置Server ...
- XAMPP + PhpStorm + Xdebug本地实验环境搭建
参考: 下载合适的XDebug 点击这里,选择合适xdebug XAMPP配置 php_xdebug-xxxx.dll 拷贝dll至 D:\XAMPP\php\ext php.ini 文末追加 [XD ...
- docker环境中neo4j导入导出
neo4j 官方文档有说明,使用 neo4j-admin restore / dump 导出和恢复数据库的时候需要停掉数据,否则会报数据库正在使用的错误:command failed: the dat ...
随机推荐
- Redis基础、应用、第三方支持组件总结
这段时间一直在研究学习Redis的相关知识,现在大概做下总结吧首先,Redis的基础方面,不说配置,就单单说下Redis数据类型:Redis 五大数据类型有String 类型,Hash 类型,List ...
- 路由网关---zuul
Zuul:Zuul 是在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架.Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门. 在微服务盛行的时代,客户端与系统之 ...
- javascript事件绑定和普通事件的区别
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- Good Bye 2018 (A~F, H)
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...
- LINUX文件及目录管理命令基础
Linux命令行组成结构 Linux命令结构 在Linux中一切皆文件,一切皆命令! 命令提示符: [root@tt ~]# [xiaohui@tt ~]$ Linux命令行常用快捷键 ctrl + ...
- python系统编程(一)
进程的创建-fork 1. 进程 VS 程序 编写完毕的代码,在没有运行的时候,称之为程序 正在运行着的代码,就成为进程 进程,除了包含代码以外,还有需要运行的环境等,所以和程序是有区别的 2. fo ...
- 配置魔药 [NOIP模拟] [DP] [费用流]
问题描述在<Harry Potter and the Chamber of Secrets>中,Ron 的魔杖因为坐他老爸的 Flying Car 撞到了打人柳,不幸被打断了,从此之后,他 ...
- json获取数据生成动态菜单(转)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Codeforces909D Colorful Points(缩点)
http://codeforces.com/problemset/problem/909/D 直接模拟超时.要运用缩点的方法,把相同的一段缩成一点,记录有几个. 对于非首尾的缩点每次-2,首尾的-1. ...
- 获取gcc和clang的内置宏定义
下面是对Gcc的内置宏定义的解释: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html https://github.co ...