docker-symfony
docker-symfony copied to clipboard
XDebug not working in PHPstorm on Windows
This probably isn't a real issue but I don't get XDebug to work on my machine. Can anyone point at a good tutorial or give some pointers?
Just guessing but the xdebug install part mentions port 9001 but it's neither exposed in the Dockerfile nor in the docker-compose.yml so try adding
ports:
- 9001:9001
to the php service in docker-compose.yml
Hi,
Under OS X it does not work either. Maybe I am missing something? I have tried changing the port to 9002, both in IDE and php configuration, just in case, but it still does not work.
Is there any special PHPStorm configuration that needs to be done?
Thank you.
I'm trying to making it work since 3 days,
If you set the port binding, you'll be unable to listen it with phpstorm, so unfortunately the solution of @Selion05 doesn't work.
I have set a bunch of options into xdebug, and i'm now inserting a xdebug.ini in the container.
Here is a sample of the file :
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=PHPSTORM
xdebug.remote_host=172.17.133.129
xdebug.remote_log = "/var/www/symfony/var/logs/xdebug.log"
In these file you'll find two interesting lines :
- The remote_host (you can find the ip host by doing a simple ipconfig in cmd)
- The remote log.
after tailing the log, i've finally found out that the problem was coming from the connection was this one :
I: Connecting to configured address/port: 172.17.133.129:9001.
E: Time-out connecting to client. :-(
Here is my docker-compose.yml :
php:
build:
context: php7-fpm
args:
TIMEZONE: ${TIMEZONE}
volumes:
- ${SYMFONY_APP_PATH}:/var/www/symfony
- ./logs/symfony:/var/www/symfony/var/logs
- ${SYMFONY_APP_PATH}:/var/www/symfony/var/logs
environment:
XDEBUG_CONFIG: "remote_host=172.17.133.129"
expose:
- "9000"
- "9001"
extra_hosts:
- "dockerhost:172.17.133.129"
So, the problem seems to come from the php container who is unable to connect to the host machine... But can't make it work :/
I got it working now on Windows. Xdebug in the PHP-FPM container was unable to send traffic back to the host. In other words, the IP that xdebug.remote_connect_back
was using wasn't working. The solution was to configure the IP-address of the host manually with the xdebug.remote_host entry
. You can use the DNS entry that is installed in the container by Docker docker.for.win.localhost
for Windows or docker.for.mac.localhost
if you're on OSX.
Here is my Dockerfile, note that I added phpcs to it at the end:
FROM php:7.1-fpm
ARG TIMEZONE
MAINTAINER Maxence POUTORD <[email protected]>
RUN apt-get update && apt-get install -y \
openssl \
git \
unzip
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"
RUN docker-php-ext-install pdo pdo_mysql
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_host=docker.for.win.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo 'alias sf="php app/console"' >> ~/.bashrc
RUN echo 'alias sf3="php bin/console"' >> ~/.bashrc
RUN curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
RUN mv phpcs.phar /usr/local/bin/phpcs
RUN chmod +x /usr/local/bin/phpcs
WORKDIR /var/www/free-energy/symfony
I do see warnings that I haven't been able to solve yet though: 'cannot load Xdebug because it was already loaded'. If anyone knows what that's all about, give a shout.
docker-compose.yml (ports untouched, listening on 9000 in PHPSTORM):
# https://github.com/maxpou/docker-symfony
version: '2.1'
services:
nginx:
build: nginx
ports:
- 80:80
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
php:
build:
context: php7-fpm
args:
TIMEZONE: ${TIMEZONE}
volumes:
- ${SYMFONY_APP_PATH}:/var/www/free-energy/symfony
- ./logs/symfony:/var/www/free-energy/symfony/app/logs
environment:
PHP_IDE_CONFIG: serverName=free-energy.org
db:
image: mysql
volumes:
- "./.data/db:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- 3306:3306
elk:
image: willdurand/elk
ports:
- 81:80
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- php
- nginx
Thank you @progonkpa I'll test that later today :)
Okay, so after testing it, it is possible to integrate the xdebug way with the PR #81
The fact that there is a fast_cgi config make it possible
here is my config :
# See https://github.com/docker-library/php/blob/master/7.1/fpm/Dockerfile
FROM php:7.1-fpm
ARG TIMEZONE
MAINTAINER Maxence POUTORD <[email protected]>
RUN apt-get update && apt-get install -y \
openssl \
git \
unzip \
libpng-dev \
g++ \
libicu-dev \
libxslt-dev
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"
# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install pdo pdo_mysql gd exif opcache && docker-php-ext-enable opcache
# install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo 'memory_limit = 1024M' >> /usr/local/etc/php/conf.d/memory-limit-php.ini
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN docker-php-ext-configure xsl
RUN docker-php-ext-install xsl
#RUN sed -i 's/memory_limit = .*/memory_limit = '1024M'/' /etc/php/cli/php.ini
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "\rxdebug.remote_host=docker.for.win.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo 'alias sf="php bin/console"' >> ~/.bashrc
WORKDIR /var/www/symfony
my xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=PHPSTORM
xdebug.remote_log = "/var/www/symfony/var/logs/xdebug.log"
My container :
php:
build:
context: php7-fpm
args:
TIMEZONE: ${TIMEZONE}
volumes:
- ${SYMFONY_APP_PATH}:/var/www/symfony
- ./logs/symfony:/var/www/symfony/var/logs
- ${SYMFONY_APP_PATH}:/var/www/symfony/var/logs
expose:
- "9000"
- "9001"
My config in phpstorm :