Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. Docker is very popular now. I am a PHP developer when using dock I got some problem when running many containers. How to setting debug in PHP with docker? That is a question that you will also get.
Xdebug is a PHP extension which provides debugging and profiling capabilities. It uses the DBGp debugging protocol. The debug information that Xdebug can provide includes the following: stack and function traces in error messages with full parameter display for user defined functions; function name, file name.
After research on Internet, I have been found a way to easy setting Docker with Xdebug. I hope I can help you somehow.
I am using PHPSTORM and Linux mint in this demo.
Step one: Install xdebug on PHP container.
In docker file.
RUN pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug RUN echo 'zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so"' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.remote_port=9000' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.remote_enable=1' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.remote_autostart = 0' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.remote_connect_back=0' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.remote_host=10.161.206.246' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.idekey=PHPSTORM' >> /usr/local/etc/php/php.ini RUN echo 'xdebug.max_nesting_level=1000' >> /usr/local/etc/php/php.ini
The 10.161.206.246 is your IP address.
To get your IP address you can type at terminal command ifconfig in Linux and Mac Os or ipconfig if you are in Window.
After that you can run
docker-compose up --build -d
To check xdebug in your PHP image you can use
Step two: config on PHPSTORM
Create new server run a website on phpstorm and mapping source local and source on your server.
126.96.36.199 is IP your network on docker when setting web server.
After that, you set a config xdebug
You can use Xdebug helper to create xdebug session.
Start xdebug on phpstorm, create a break point and visit your url.
My English is not good but I try to share with you. Leave your comment I try to answer all.