我的github地址:https://github.com/shmilylbelva/dnmp
一、Docker中安装Xdebug
1、在dockerfile下添加Xdebug代码
打开php72下的dockerfile文件(对应到你自己的dockerfile文件),在末尾添加上以下内容(安装Xdebug):
# Install Xdebug extension from source
RUN pecl install xdebug && docker-php-ext-enable xdebug
2、在php.ini中末尾添加如下代码
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "192.168.0.107"//这里的host地址不能为127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_log = "/var/log/dnmp/php.xdebug.log"
Xdebug.idekey="PHPSTORM"//你先这么写,后面会说到
3、重新build php容器
在terminal中
docker container ls
docker stop 595 //595是我的php容器id
docker rm 595
docker-compose up -d --build //重新启动容器,会自动更新刚刚的dockerfile
据说是因为容器中不能直接通过127.0.0.1访问容器主机,所以这里的ip正确配置往下看。
4、打开phpstorm->preferences->Languages & Frameworks->PHP->Debug

上图中的IDE IP就是php.ini中的remote_host的地址

上图中的IDE key 就是php.ini中的idekey

5、用phpinfo()可以查看Xdebug的安装情况

6、配置断点调试
点击 Edit Configurations
这里我将该断点调试命名为tp5,调试的URL为/banner/2


当调试开始后,进入调试状态可以看到断点上有一个小勾,点击断点调试按钮进入洗衣歌调试点,同时可以看到调试信息。

如果你经过以上步骤未能成功使用Xdebug,可以查看/log/php.xdebug.log日志,进行针对性的修改

网友评论