我的github地址:https://github.com/shmilylbelva/dnmp
一、Docker中安裝Xdebug
1、在dockerfile下添加Xdebug代碼
打開php72下的dockerfile文件(對(duì)應(yīng)到你自己的dockerfile文件),在末尾添加上以下內(nèi)容(安裝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"http://這里的host地址不能為127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_log = "/var/log/dnmp/php.xdebug.log"
Xdebug.idekey="PHPSTORM"http://你先這么寫,后面會(huì)說到
3、重新build php容器
在terminal中
docker container ls
docker stop 595 //595是我的php容器id
docker rm 595
docker-compose up -d --build //重新啟動(dòng)容器,會(huì)自動(dòng)更新剛剛的dockerfile
據(jù)說是因?yàn)槿萜髦胁荒苤苯油ㄟ^127.0.0.1訪問容器主機(jī),所以這里的ip正確配置往下看。
4、打開phpstorm->preferences->Languages & Frameworks->PHP->Debug

Debug配置
上圖中的IDE IP就是php.ini中的remote_host的地址

DBGp Proxy
上圖中的IDE key 就是php.ini中的idekey

配置servers
5、用phpinfo()可以查看Xdebug的安裝情況

image.png
6、配置斷點(diǎn)調(diào)試
點(diǎn)擊 Edit Configurations
image.png
這里我將該斷點(diǎn)調(diào)試命名為tp5,調(diào)試的URL為/banner/2

配置

打斷點(diǎn)
當(dāng)調(diào)試開始后,進(jìn)入調(diào)試狀態(tài)可以看到斷點(diǎn)上有一個(gè)小勾,點(diǎn)擊斷點(diǎn)調(diào)試按鈕進(jìn)入洗衣歌調(diào)試點(diǎn),同時(shí)可以看到調(diào)試信息。

調(diào)試開始
如果你經(jīng)過以上步驟未能成功使用Xdebug,可以查看/log/php.xdebug.log日志,進(jìn)行針對(duì)性的修改

log