Skip to content

docker+phpstorm+远程debug

docker PHP多版本部署 + 安装xdebug模块 配置php.ini

docker PHP多版本部署

docker run -d -p 1001:80 -v /Users/dkk/WWW:/var/www/html php:5.6-apache
docker run -d -p 1003:80 -v /Users/dkk/WWW:/var/www/html php:7.2-apache
docker run -d -p 1004:80 -v /Users/dkk/WWW:/var/www/html php:7.3-apache
docker run -d -p 1005:80 -v /Users/dkk/WWW:/var/www/html php:7.0-apache
docker run -d -p 1002:80 -v /Users/dkk/WWW:/var/www/html php:7.4.5-apache
docker run -d -p 1001:80 -v /Users/dkk/WWW:/var/www/html php:7.4.8-apache

安装xdebug模块

pecl install xdebug && docker-php-ext-enable xdebug
// php5.6 需要指定版本安装 pecl install xdebug-2.5.0

然后运行php -m 发现已经安装好xdebug模块

修改php.ini文件

先安装vim 换个源
cat /etc/issue 要换Debian GNU/Linux 10的源

echo 'deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
 deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
 deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
 deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
 deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
 deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
 deb http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib
 deb-src http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib'> /etc/apt/sources.list

apt update && apt install -y vim

cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
vim /usr/local/etc/php/php.ini
[XDebug]
xdebug.collect_return=On
xdebug.remote_enable = On
xdebug.remote_port=9001
xdebug.remote_handler = dbgp
xdebug.remote_host = 192.168.3.58
xdebug.var_display_max_depth = 10
xdebug.idekey= PHPSTROM
xdebug.remote_log = /var/log/php-fpm/x-debug-remote.log
xdebug.collect_params=On
xdebug.auto_trace=on
xdebug.profiler_enable=On

写进去之后重启apache服务 apache2ctl restart

重新登入docker exec -it b5c bash

查看phpinfo

配置PHPstorm

1

基本上就没什么问题了

chrome 安装 debug插件 就ok了