PhpStorm+Xdebug+Docker实现断点调试(Mac平台亲测)

PhpStorm+Xdebug+Docker实现断点调试(Mac平台亲测)

  1. 配置xdebug

[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=PHPSTORM
xdebug.remote_host=127.0.0.1

```
  1. 设置docker的环境变量XDEBUG_CONFIG,并运行docker run -p 9000:9000 --name php-fpm -v $PWD/www:/var/www/html -v $PWD/php/php-fpm.d/www.conf:/usr/local/etc/php-fpm.d/www.conf -v $PWD/php/conf:/usr/local/etc/php -e XDEBUG_CONFIG="remote_host=192.168.31.5" -d ysnows/php7.2.3-fpm:latest,其中,remote_host就是运行phpstorm那台机器的ip地址,mac可通过ifconfig en0获取

    image

  2. 配置PhpStorm,如图

    1. image
    2. image
  3. 安装xdebug_helper插件,并配置为PhpStorm

    image

  4. 开启插件的debug功能


    image
  1. 打断点,访问,愉快的调试


    image
image

参考:
1. Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. 以上是在浏览器中访问的时候,进行断点调试;还有一个需求是,在php index.php运行命令行的时候进行调试,解决方案:

    1. 建立Server
      image
    2. 设置Docker镜像的环境变量


      image
    3. Start Listenning


      image
    4. index.php中添加断点,并在Docker容器中运行php index.php即可断点调试
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容