phpstorm 断点调试虚拟机中php项目(web application 项目)(PHP xdebug调试)

本文详细介绍了如何在Mac环境下使用PHPStorm和xdebug进行PHP项目的断点调试,包括在虚拟机中安装配置xdebug,以及在PHPStorm中设置调试环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:代码开发环境mac  ,开发工具phpstorm;

php项目运行环境 ; vmware 虚拟机中 , 操作系统 centos6.7, php 运行环境 LNMP, php 版本 7.3 ;

 

目标/需求:在开发环境中断点调试 PHP项目代码;最大限度根据真实操作场景来debug 如: 浏览器访问链接 http://laravel55.liang.com/orm1后;可以断点调试程序

应用: 平时项目开发中使用(这种情况较少);分析复杂框架的执行过程,函数调用过程等,方法其一,如分析laravel, 框架;开源项目源码分析;接手他人复杂代码,还未熟悉时等等。总之debug 断点调试时分析代码好的手段之一。

mac 本机IP: 192.168.199.197 ;

虚拟机(work) IP : 192.168.199.129

 

步骤一: work 中 给php7.3  安装 xdebug 扩展

pecl 安装 xdebug扩展

1032  wget http://pecl.php.net/get/xdebug-2.7.0alpha1.tgz

1043  pecl install xdebug-2.7.0beta1.tgz 

注意;2.6.1 stable版本 安装会出错,所以选择beta版本

 

步骤二:在php.ini  中添加 xdebug 相关配置

[xdebug]
zend_extension=/alidata/server/php7.3/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=192.168.199.197
xdebug.remote_port=9000
xdebug.idekey=PHPSTROM

 

配置项含义:remote_enable  = 1 标示允许 其他 程序(如phpstorm 浏览器等) 与 php程序联系;

remote_host 一定要写不然 php xdebug 怎么知道谁要和他联系呢,总不能随意来一个都能与 php程序来联系吧这也不安全;

remote_host  remote_port;   其实是告诉 php 程序 将来 有个 主机 192.168.199.197 端口是9000 的这个程序(phpstorm )会和你联系的。

remote_host  remote_port 一定不能省略!!!

 

步骤三:phpstorm(它是安装在我的mac真机上) 中配置

php CLI Interpreter 是 不需要配置的!!!;原因是 phpstorm  使用的是 work 中php xdebug; phpstorm 只是告诉 work 中php  我哪些文件什么地方是断点;还有就是 接收 work php 返回来的debug信息(如变量信息,如 响应的浏览器的html 信息 等)

浏览器中不需要安装 xdebug !!!

图一:

 

debug port 配置:

注意 一定要和 work  中 php.ini 中 xdebug.remote_port  端口号一致 为 9000:

图二:

800

 

DBGp Proxy 中 不需要设置!!!因为这可能是其他调试方式中需要配置的,本案例不需要!!!

 

设置 Servers:

注意 laravel55.liang.com  这个域名 一定要在 mac 真机 /etc/hosts 中加上

注意 Use path mapping 一定 加上,并且mac 真机 和  work  中 php 项目路径一定对应正确!!!

图四:

 

步骤四:

创建 Run/Debug  Configurations

  1. 选择 Edit Configurations   2.  对话框中左上角 “+ ”号 选择 “PHP Web Page”; 3. 设置 /路由 等

图三:

验证: 经过以上步骤debug 就配置好了 ;在index.php(入口文件中,及controller 中打几个断点);点击 debug 虫子图标;

结果说明:

注注意; 可以看到 途中 PHP_OS 中值为 Linux ;验证了 执行这个PHP代码的其实是 work 中php程序;

图五:

此时浏览器中效果如图:

结果说明:图 右上角 小圈一直转到标示响应还没结束

图六:

 

书名:Beginning PHP6, Apache, MySQL Web Development 出版社:Wrox 作者:Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass ISBN: 978-0-470-39114-3 简介: 这本书被誉为PHP APACHE MYSQL新圣经,覆盖多平台,书中例子适合各种开发人员学习和研究。 目录: Introduction ......................................................................................................... xxiii Part I: Movie Review Web Site Chapter 1: Configuring Your Installation ..........................................................3 Chapter 2: Creating PHP Pages Using PHP6 ..................................................19 Chapter 3: Using PHP with MySQL ................................................................77 Chapter 4: Using Tables to Display Data ......................................................105 Chapter 5: Form Elements: Letting the User Work with Data ........................131 Chapter 6: Letting the User Edit the Database .............................................153 Chapter 7: Manipulating and Creating Images with PHP...............................175 Chapter 8: Validating User Input .................................................................217 Chapter 9: Handling and Avoiding Errors ......................................................241 Part II: Comic Book Fan Site Chapter 10: Building Databases ..................................................................263 Chapter 11: Sending E-mail .........................................................................315 Chapter 12: User Logins, Profiles, and Personalization .................................355 Chapter 13: Building a Content Management System ..................................407 Chapter 14: Mailing Lists ............................................................................469 Chapter 15: Online Stores ...........................................................................505 Chapter 16: Creating a Bulletin Board System .............................................557 Chapter 17: Using Log Files to Improve Your Site .........................................627 Chapter 18: Troubleshooting .......................................................................641 Appendix A: Answers to Exercises ..............................................................649 Appendix B: PHP Quick Reference...............................................................685 Appendix C: PHP6 Functions .......................................................................695 Appendix D: MySQL Data Types ...................................................................753 Appendix E: MySQL Quick Reference ...........................................................757 Appendix F: Comparison of Text Editors .......................................................761 Appendix G: Choosing a Third-Party Host .....................................................765 Appendix H: An Introduction to PHP Data Objects ........................................769 Appendix I: Installation and Configuration on Linux ......................................777 Index .........................................................................................................785
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值