- For your local dev, create a
Dockerfile
that is based on your production image and simply installxdebug
into it. Exemple:
FROM php:5
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
- Get you local IP address (
ip -o -4 addr list ${MY_NETWORK_INTERFACE:-eth0} | awk '{print $4}' | cut -d/ -f1
) - Start your container with the following environment variables:
XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}"
-
Simple
docker
run:docker run -e XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}" your-image
-
With
docker-compose
:# docker-compose.yml foo: build: path/to/Dockerfile environment: XDEBUG_CONFIG: "remote_host={{YOUR_IP_ADDRESS}}" PHP_IDE_CONFIG: "serverName=my.local"
- In Intellij/PHPStorm go to:
Languages & Frameworks
>PHP
>Servers
> and set the following settings:
- Name: name of your server, should be equal to value in
PHP_IDE_CONFIG
variable
Then you're all set and can start listening for PHP Debug connections from your IDE.
Happy debugging!
Thank you for this tutorial.
I just want to help out a bit how I managed to set it up with my client's docker. Just a few points on the above tutorial.
To get the IP I used this syntax:
Real example on my computer:
I started changing files
fpm.docker
:Take a note at the _ Install Xdebug_ section.
In the end, I went straight to
docker-compose.yml
and changed this:In the PHPStorm small changes were required the server needed to be renamed to
jo
and the mappings to/var/www/
since we are in the container not on my local machine anymore.Finally for all of you guys there when you make changes to docker files or
docker-compose.yml
you need to rebuild it with this:Just one more thing, on all of you curios how I debug xdebug is with simple
phpinfo()
.Here are those images that I wanted to share:
Hope it will help somebody.
Thanks again to all for this.