简体   繁体   English

如何在Ubuntu 16.04上设置Docker + PhpStorm + xdebug

[英]How to setup Docker + PhpStorm + xdebug on Ubuntu 16.04

My problem is that xdebug doesn't work when I start listening port. 我的问题是当我开始监听端口时xdebug不起作用。 I think PhpStorm can't link with xdebug. 我认为PhpStorm无法与xdebug链接。 I just get debugger panel variables are not available. 我只是得到调试器面板变量不可用。 It's looks like xdebug have not correct settings. 它看起来像xdebug没有正确的设置。

Software and versions used: 使用的软件和版本:

Ubuntu 16.04 LTS
Docker v 17.06
docker-compose 1.15

So I was trying many times setup xdebug + Docker + PhpStorm but cannot do it. 所以我多次尝试设置xdebug + Docker + PhpStorm但不能这样做。 I've read many tutorials but nothing haven't helped me. 我已经阅读了很多教程,但没有任何帮助我。

My docker-compose.yml looks like this: docker-compose.yml看起来像这样:

version: '3'
services:
    web:
        image: nginx:latest
        ports:
            - "80:80"
        restart: on-failure
        volumes:
            - "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
            - "./etc/ssl:/etc/ssl"
            - "./project:/var/www/html/project"
        depends_on:
            - php
            - db

    php:
        image: nanoninja/php-fpm
        restart: on-failure
        volumes:
            - "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
            - "./project:/var/www/html/project"
    db:
        image: mysql
        container_name: ${MYSQL_HOST}
        restart: on-failure
        env_file:
            - ".env"
        environment:
            - MYSQL_DATABASE=${MYSQL_DATABASE}
            - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
            - MYSQL_USER=${MYSQL_USER}
            - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION
        ports:
            - "8988:3306"
        volumes:
            - "./data/db/mysql:/var/lib/mysql"

My xdebug.ini is: 我的xdebug.ini是:

xdebug.default_enable=0
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=0
xdebug.idekey="PHPSTORM"
xdebug.profiler_enable=0
xdebug.remote_host=localhost

PhpStorm settings: PhpStorm设置:

在此输入图像描述

在此输入图像描述

在此输入图像描述

在此输入图像描述

I found out solution how to run xdebug. 我找到了如何运行xdebug的解决方案。

1) First of we need create a new static route that will based on your network device. 1)首先我们需要创建一个基于您的网络设备的新静态路由。 For create new static route: run in terminal ifconfig 对于创建新的静态路由:在终端ifconfig运行

and found out the exists network device. 并找出了存在的网络设备。 In my situation name of device will be as 在我的情况下,设备名称将为

wlp4s0

在此输入图像描述

2) Go ahead. 2)继续。 Let's begin create the static route. 让我们开始创建静态路由。 In terminal run command like this: 在终端运行命令中,如下所示:

> sudo ip addr add 10.254.254.254/24 brd + dev wlp4s0 label wlp4s0:1

3) Now if you run again ifconfig you'll see new static route: 3)现在,如果再次运行ifconfig您将看到新的静态路由: 在此输入图像描述

4) Update 4)更新

xdebug.ini

file add: 文件添加:

xdebug.remote_host=10.254.254.254

5) Update docker.compose.yml file: in php section add: 5)更新docker.compose.yml文件:在php部分添加:

environment:
    PHP_IDE_CONFIG: "serverName=project-docker"
    PHP_XDEBUG_ENABLED: 1
    XDEBUG_CONFIG: remote_host=10.254.254.254

6) The last thing is update phpstorm settings. 6)最后一件事是更新phpstorm设置。

Server settings: 服务器设置: phpstorm设置 Remote debug config: 远程调试配置: phpstorm设置 7) And profit xdebug is working: 7)利润xdebug正在运作: xdebug正在工作

Linux上的Docker允许Xdebug自动连接回主机系统,因此您只需设置xdebug.remote_connect_back=1xdebug.inixdebug.remote_host xdebug.ini

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM