Reputation: 1277
I wanted to separate all my development tools from the main php-fpm and nginx containers. So I have basically 3 containers named as php-fpm runs on port 9000, nginx on port 80 and dev-tools. I have installed xdebug, composer etc on my dev-tools container but I am confused how to configure xdebug so that it will work with php-fpm container and can debug my website ? Second question does xdebug need php-cli or php-fpm to run itself?
#dev-tools
FROM php:7.2-cli-alpine
# Install the PHP extensions we need
RUN set -ex \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin -- --filename=composer.phar \
&& apk add --no-cache git \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug
Upvotes: 3
Views: 3262
Reputation: 18426
xdebug uses port 9000
by default, which conflicts with the PHP-FPM port.
You would need to change the assigned port of your PHP-FPM pool config or xdebug in php.ini. I recommend updating your PHP-FPM configuration to listen on a different port as it is less to configure for debugging with xdebug.
If you would like to change the port in PHP-FPM.
/php-fpm.d/pool.conf
[pool]
listen = 127.0.0.1:9001
Update your NGINX configuration appropriately to use the new port.
Otherwise if you would like to change the xdebug port in PHP.
php.ini
[xdebug]
xdebug.remote_port=9001
Update your debugging (PHP editor/IDE) software and firewall configuration to the new port. Alternatively use an SSH tunnel to forward the new remote port 9001 to the default local port 9000
As to your second question
xdebug only runs as an extension of PHP (php-fpm), if it is set to load in your PHP ini settings. It does not run as a separate background service.
Example:
[Browser Client -> http://example.com/path/to/script.php]
in -> [NGINX]
in -> [php-fpm /path/to/script.php]
[xdebug remote host:port] <- out
or
[terminal command line]
in -> [php /path/to/script.php]
[xdebug remote host:port] <-out
So yes, xdebug needs php-fpm or php-cli to run as they are one and the same.
If through Apache/NGINX that uses php-fpm, it will need to be loaded in your fpm configuration. If through the CLI interface, it would need to be loaded in your CLI configuration.
Keep in mind that you can run PHP with differing ini configurations based on environment. See PHP - The configuration file
Upvotes: 5