Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
597 views
in Technique[技术] by (71.8m points)

php - How to setup Docker + PhpStorm + xdebug on Ubuntu 16.04

My problem is that xdebug doesn't work when I start listening port. I think PhpStorm can't link with xdebug. I just get debugger panel variables are not available. It's looks like xdebug have not correct settings.

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. I've read many tutorials but nothing haven't helped me.

My docker-compose.yml looks like this:

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.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:

enter image description here

enter image description here

enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Docker on Linux allows Xdebug to automatically connect back to the host system so you can just set xdebug.remote_connect_back=1 and leave out the xdebug.remote_host in your xdebug.ini.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...