markdown PHPStorm远程调试Docker容器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown PHPStorm远程调试Docker容器相关的知识,希望对你有一定的参考价值。

# Run on Host
```shell
$ docker-machine upgrade <VM NAME>
```

# Run on Environment PHP-Installed Container
```shell
$ pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug
```

# Put the Following Code to Your XDebug.ini File
Your `ini` file is located under `/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini`.
```ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1 #Set this to 1 in order for xdebug to start when the container starts
xdebug.remote_connect_back=1 #Set this to 1 if you don't want to provide remote_host
\!h xdebug.idekey=<Unique IDE Key to be also set on PHPStorm config>
#xdebug.remote_host=<HOST LOCAL IP ADDRESS>
```

# Extra Info
If you set `xdebug.remote_connect_back=1` then you don’t have to provide
`xdebug.remote_host=<HOST LOCAL IP ADDRESS>` but you have to enable
`Start Listening for PHP Debug Connections` in PHPStorm.

# PHPStorm Config

## PHP Server
1. Create a server from `Languages & Frameworks > PHP > Servers`.
2. Name your server to whatever you want.
3. Host IP address is your `VM's IP address`.
4. Port is `80` if you are not listening from any other port in your web server in VM.
5. Debugger is `XDebug`.
6. Check `Use path mappings`.
7. Under `Absolute path on the server` section write where your projetc is located in your docker container. (i.e. `/var/www`)

## Debug Config
1. Click `Run > Edit Configurations...`.
2. Add a `PHP Remote Debug`.
3. Name it to whatever you want.
4. Check `Filter connection by IDE key`.
5. Select the server you have created before from the drowdown list.
6. Write  your `IDE key`. This is the same key you have written in your `XDebug.ini` file as `xdebug.idekey`. These two have to match.

## Debugging
1. Click `Run > Start Listening for PHP Debug Connections`.
2. Set a breakpoint in your PHP code.
3. Click `Run > Debug`.
4. Go to your browser and navigate to your web site.
5. You will see that code is stopped at the breakpoint and variables are listed in Debug panel of PHPStorm.

以上是关于markdown PHPStorm远程调试Docker容器的主要内容,如果未能解决你的问题,请参考以下文章

PHPStorm、Xdebug 和远程调试(在 phpstorm 中使用 FTP)

使用 PHPStorm 解决 PHPUnit xdebug 远程调试问题

phpstorm+xdebug 远程调试

如何使用 phpstorm 和 Xdebug 设置远程调试

phpstorm + xdebug 远程断点调试

如何使用 PhpStorm / WebStorm 连接到远程 nodejs 调试会话?