As title says, cant hit breakpoints if I run docker compose without sudo.
When I run sudo docker compose up --build
, everything works.
When I run docker compose up
, I can access my web app on htpp://web.app:8888
, it works flawlessly but I cant hit any breakpoints.
Why is that happening? I have read countless responses on StackOverflow, Medium articles, and watched tons of YouTube videos on setting up Docker + Xdebug + PhpStorm. Nothing worked so far, at least not without running Docker with sudo.
This is my current setup (I am on Ubuntu 20.04):
xdebug.ini
zend_extension=xdebug.so
xdebug.mode=develop,coverage,debug
xdebug.idekey=docker
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.discover_client_host=1
xdebug.client_host=host.docker.internal
docker-compose.yml
version: '3.8'
services:
nginx:
container_name: nginx
image: nginx:latest
ports:
- "8888:80"
volumes:
- ../www/myapp:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- db
php:
container_name: php
build: ./php
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- ../www/myapp:/var/www/html
- ./php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
working_dir: /var/www/html
db:
container_name: db
image: postgis/postgis:15-3.5
environment:
POSTGRES_DB: myapp
POSTGRES_USER: myapp
POSTGRES_PASSWORD: myapp
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
db-test:
container_name: db-test
image: postgis/postgis:15-3.5
environment:
POSTGRES_DB: myapp
POSTGRES_USER: myapp
POSTGRES_PASSWORD: testtest
ports:
- "5433:5432"
volumes:
- pgdata-test:/var/lib/postgresql/data
volumes:
pgdata:
pgdata-test:
PHP Dockerfile
# Use the official PHP 7.4 FPM image
FROM php:7.4-fpm
# Install system dependencies and required PHP extensions
RUN apt-get update && apt-get install -y \
curl \
unzip \
libpq-dev \
libicu-dev \
libjpeg-dev \
libfreetype6-dev \
libpng-dev \
libmagickwand-dev \
libzip-dev \
git \
zip \
&& docker-php-ext-install \
pdo pdo_pgsql \
intl \
pcntl \
gd \
zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& pecl install xdebug-3.1.6 \
&& docker-php-ext-enable xdebug
# Install Composer
RUN curl -sS | php -- --install-dir=/usr/local/bin --filename=composer
# Disable expose_php in php.ini
# RUN echo "expose_php = Off" >> /usr/local/etc/php/conf.d/custom.ini
# Set additional PHP configurations if needed
# RUN echo "some_other_config = value" >> /usr/local/etc/php/conf.d/custom.ini
# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
ARG UNAME=www-data
ARG UGROUP=www-data
ARG UID=1000
ARG GID=1001
RUN usermod --uid $UID $UNAME
RUN groupmod --gid $GID $UGROUP
PhpStorm Server settings (the mappings are correctly set up):
PhpStorm Debug settings:
When I try to "Validate Debugger Configuration on Web Server", I choose "Local Web Server or Shared Folder" and using :8888
, I get Specified URL is not reachable, caused by: 'Request failed with status code 404'
despite using sudo or not.
I put xdebug_info();
in the code for one of my controller's actions. I can access xdebug page. It changes based on if I used sudo or not.
This is with sudo:
This is without sudo:
If you need any more relevant info ask and I can provide it.
With sudo the breakpoints in PhpStorm are instantly hit, without sudo they don't work at all, no other changes in the configs.
As title says, cant hit breakpoints if I run docker compose without sudo.
When I run sudo docker compose up --build
, everything works.
When I run docker compose up
, I can access my web app on htpp://web.app:8888
, it works flawlessly but I cant hit any breakpoints.
Why is that happening? I have read countless responses on StackOverflow, Medium articles, and watched tons of YouTube videos on setting up Docker + Xdebug + PhpStorm. Nothing worked so far, at least not without running Docker with sudo.
This is my current setup (I am on Ubuntu 20.04):
xdebug.ini
zend_extension=xdebug.so
xdebug.mode=develop,coverage,debug
xdebug.idekey=docker
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.discover_client_host=1
xdebug.client_host=host.docker.internal
docker-compose.yml
version: '3.8'
services:
nginx:
container_name: nginx
image: nginx:latest
ports:
- "8888:80"
volumes:
- ../www/myapp:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- db
php:
container_name: php
build: ./php
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- ../www/myapp:/var/www/html
- ./php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
working_dir: /var/www/html
db:
container_name: db
image: postgis/postgis:15-3.5
environment:
POSTGRES_DB: myapp
POSTGRES_USER: myapp
POSTGRES_PASSWORD: myapp
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
db-test:
container_name: db-test
image: postgis/postgis:15-3.5
environment:
POSTGRES_DB: myapp
POSTGRES_USER: myapp
POSTGRES_PASSWORD: testtest
ports:
- "5433:5432"
volumes:
- pgdata-test:/var/lib/postgresql/data
volumes:
pgdata:
pgdata-test:
PHP Dockerfile
# Use the official PHP 7.4 FPM image
FROM php:7.4-fpm
# Install system dependencies and required PHP extensions
RUN apt-get update && apt-get install -y \
curl \
unzip \
libpq-dev \
libicu-dev \
libjpeg-dev \
libfreetype6-dev \
libpng-dev \
libmagickwand-dev \
libzip-dev \
git \
zip \
&& docker-php-ext-install \
pdo pdo_pgsql \
intl \
pcntl \
gd \
zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& pecl install xdebug-3.1.6 \
&& docker-php-ext-enable xdebug
# Install Composer
RUN curl -sS https://getcomposer./installer | php -- --install-dir=/usr/local/bin --filename=composer
# Disable expose_php in php.ini
# RUN echo "expose_php = Off" >> /usr/local/etc/php/conf.d/custom.ini
# Set additional PHP configurations if needed
# RUN echo "some_other_config = value" >> /usr/local/etc/php/conf.d/custom.ini
# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
ARG UNAME=www-data
ARG UGROUP=www-data
ARG UID=1000
ARG GID=1001
RUN usermod --uid $UID $UNAME
RUN groupmod --gid $GID $UGROUP
PhpStorm Server settings (the mappings are correctly set up):
PhpStorm Debug settings:
When I try to "Validate Debugger Configuration on Web Server", I choose "Local Web Server or Shared Folder" and using http://my.app:8888
, I get Specified URL is not reachable, caused by: 'Request failed with status code 404'
despite using sudo or not.
I put xdebug_info();
in the code for one of my controller's actions. I can access xdebug page. It changes based on if I used sudo or not.
This is with sudo:
This is without sudo:
If you need any more relevant info ask and I can provide it.
With sudo the breakpoints in PhpStorm are instantly hit, without sudo they don't work at all, no other changes in the configs.
Share Improve this question edited Mar 18 at 17:32 LazyOne 166k48 gold badges414 silver badges415 bronze badges asked Mar 17 at 19:08 Gustavo BottiGustavo Botti 11 bronze badge1 Answer
Reset to default 0I reproduced your configuration locally, and I was able to debug step by step without using sudo.
Your issue does not appear to be related to Xdebug, but rather to Docker permissions.
First, you can try adding the docker
group to your current user with sudo usermod -aG docker $USER
Alternatively, try uninstalling and reinstalling Docker to fix the permissions.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744539801a4579654.html
评论列表(0条)