Xdebug doen't connect: Virtualhosts with Apache2 and PHP-FPM

XDEBUG doesn’t work with my actual setup, but I don’t know how solve this problem… I’ve also see https://forums.docker.com/t/solved-how-to-setup-xdebug-and-phpstorm but without success…

My setup are the follows:

docker-compose.yml


version: '2'

services:

    php-fpm:
        container_name: php-worker
        build:
            context: ./php-fpm
        volumes_from:
            - volumes_source
        links:
            - workspace
        expose:
            - "9000"

    apache2:
        container_name: apache-worker
        build:
            context: ./apache2
            args:
                - PHP_SOCKET="php-worker:9000"
        volumes_from:
            - volumes_source
        volumes:
            - ./logs/apache2:/var/log/apache2
            - ./conf/apache2/vhosts:/etc/apache2/sites-enabled
            - ./conf/apache2/ssl:/etc/apache2/ssl
        ports:
            - "80:80"
            - "443:443"
            - "9000:9000"
        links:
            - php-fpm

    volumes_source:
        image: tianon/true
        volumes:
            - ./proj:/var/www/proj

and clearly runs via docker-compose up -d apache2.

In php-fpm, named php-worker, I’ve put /usr/local/etc/php/conf.d/xdebug.ini file:

xdebug.cli_color=1
xdebug.remote_autostart=on
xdebug.remote_connect_back=0
xdebug.remote_mode=req
xdebug.remote_handler=dbgp
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.remote_host=localhost
xdebug.idekey=MYXDEBUG
xdebug.remote_log=/tmp/log/xdebug.log-e 
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so

And in Netbeans (also tried in Sublime Text 3) I’ve setted idekey to MYXDEBUG and port to 9000 and XDEBUG is enabled (phpinfo(); confirm this).

To manage multiple sites, in ./proj folder I’ve inserted a site folder named site1, and in apache2 Virtualhost the follow:

<VirtualHost *:80 >
    ServerAdmin admin@example.com
    ServerName site1.com
    ServerAlias site1
    DocumentRoot /var/www/proj/site1/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Setted DNS in /etc/hosts

127.0.0.1     site1

And in browser URL http://site1/ works as aspected but… not XDEBUG, that try to connect, but without success.

I’m working on macbook pro, and docker for mac beta versio 1.12.2-rc1.

In xdebug.ini I’ve tried to change xdebug.remote_host to 127.0.0.1, localhost, site1 and 172.20.0.1 (the gateway of php-worker container) and nothing works…

I hope someone could help me, please!

The problem is that localhost and 127.0.0.1 inside the container isn’t your host machine, it’s the VM layer. 172.20.0.1 isn’t your host necessarily either. As far as I know, Docker for Mac doesn’t provide network information about your host. There has been rounds of these kinds of questions around the forum as well as on Docker’s Github issue tracker.

See How to reach MacOSX from Container? for options

Thanks!!!

but doesn’t work… probably I’m wrong in some step…

Refering to https://forums.docker.com/t/how-to-reach-macosx-from-container/22304/3 :slight_smile:

  • option 1: I don’t understood what to do…
  • option 2: set the IP 10.255.255.255 via ifconfig l0 and as value of xdebug.remote_host, but doesn’t work…

Since I’m not well formed about Networks, could you explain, please?!

I’ve not mentioned that I’m working with docker for mac in my Macbook, without usage of docker-machine.