mattrayner / docker-lamp

A simple LAMP image using Ubuntu, Apache, PHP and MySql in a single image
Apache License 2.0
592 stars 262 forks source link

Remote debugging with xdebug & visual studio code #101

Open ddrury opened 4 years ago

ddrury commented 4 years ago

Hi, probably another noob question, I can't get this working

Here's my Dockerfile

FROM mattrayner/lamp:latest-1804

ARG MYIP

RUN apt-get update && apt-get -y install php-intl \
    && echo "xdebug.remote_enable=on" >> /etc/php/7.4/apache2/conf.d/zz-xdebug.ini \
    && echo "xdebug.remote_host=${MYIP}" >> /etc/php/7.4/apache2/conf.d/zz-xdebug.ini \
    && echo "xdebug.remote_autostart=on" >> /etc/php/7.4/apache2/conf.d/zz-xdebug.ini \
    && echo "xdebug.remote_connect_back=0" >> /etc/php/7.4/apache2/conf.d/zz-xdebug.ini \
    && echo "xdebug.idekey=VSCODE" >> /etc/php/7.4/apache2/conf.d/zz-xdebug.ini

EXPOSE 9000
CMD ["/run.sh"]
(END)

the build command is docker build --build-arg MYIP=$(hostname -I) -t mylamp . and the run command in ~/.bash_profile is docker run -i -t -p "$APACHE_PORT:80" $MYSQL_PORT_COMMAND -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mylamp

If in the build command I change MYIP=$(hostname -I) to MYIP=$(hostname -i), I get a different IP address but it makes no difference.

I attach part of the phpinfo() output and the correct values are set (I think), I'm pretty comfortable with configuring the vscode end, but when I set a breakpoint, the code sails straight past without stopping

phpinfo.pdf

All & any help greatly appreciated! BTW I think I've tried all the suggestions from google searches

mattrayner commented 4 years ago

I think you will need to map port 9000 to your local machine:

docker run -i -t -p "$APACHE_PORT:80" -p 9000:9000 $MYSQL_PORT_COMMAND -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mylamp

Then I would think that should fix it for you

ddrury commented 4 years ago

When I do that VSCODE reports that port 9000 is in use.

I've been having a think and all the other stuff I've seen on the internet assumes that the server is in the WSL2 VM and the source code is in windows.

VSCODE installs a bunch of stuff in ~/.vscode-server (including the xdebug extension), so I think in this instance with the source in the WSL2 VM and the server in the docker container, I need to set the xdebug remote host ip to that of the WSL2 internal IP.

What do you think> - I'm a bit pushed for time at the moment but I'll give it a try. Dave