Properly setup xdebug with PHP Apache Docker Container including composer

The debugging itself works, but the Web Server Debug Validation (Run > Web Server Debug Validation) does not properly work, and I do not understand why. My setup of xdebug for my coker container can be summed up pretty much with this here.

And my docker configurations are:

Dockerfile:

FROM php:8.1-apache

WORKDIR /var/www/html/

RUN pecl install xdebug \
&& apt update \
&& apt install libzip-dev -y \
&& docker-php-ext-enable xdebug \
&& a2enmod rewrite \
&& docker-php-ext-install zip \
&& rm -rf /var/lib/apt/lists/*

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json .

RUN groupadd -r user && useradd -r -g user user
USER user
RUN composer install --no-dev

COPY . .

EXPOSE 80

docker-compose.yml:

services:

php:
build: ./php
depends_on:
- db
container_name: php-apache
ports:
- 80:80
volumes:
- ./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
# Source code
- ./php/src:/var/www/html/src
# unbind local composer components
- /php/vendor
- /php/composer.lock
- /php/composer.phar
environment:
MARIADB_HOST: localhost
MARIADB_USER: root
MARIADB_PASSWORD: top_very_secret
MARIADB_DB: apidb

adminer:
image: adminer
depends_on:
- db
restart: always
ports:
- 8080:8080

db:
image: mariadb
container_name: db
volumes:
- maria-db-storage:/var/lib/mysql
environment:
MARIADB_ROOT_PASSWORD: top_very_secret
MARIADB_DATABASE: apidb

volumes:
maria-db-storage:

The folder structure is:

project_abc_root
    php
        src
        Dockerfile
        composer.json
        index.php
    docker-compose.yml

If I now launch

docker-compose up

I can successfully load the contents at http:localhost, or also at http:localhost:80. 200, Everything's fine.

When I click on "start listening for debugging connections" within the IDE; I can also successfully start the configured step debuggings, all of that works. Now I have two questions:

  1. When I go to Run > Web Server Debug Validation, and then select "Local Web Server orShared Folder", then type "C:\Users\....project_abc_root" as the value of "Path to create validation script", and "http://localhost:80" as the value of "URL to validation script", I always get: "Specified URL is not reachable, caused by: 'Request failed with status code 404'". Why? Same if I specify  "C:\Users\....project_abc_root\php" as the value of "Path to create validation script". I've read this documentation of yours, and now countless other forum posts etc etc, and I can't really figure out why. I've also not set any kind of redirects. I also totally do not understand where you actually define path mappings that are used when ticking the option "Local Web Server orShared Folder"; there's no reference in the GUI whatsoever??
  2. As you can see from my file structure, regarding composer parts, I aim to only use composer.json in my project, while completely omitting the other composer components (vendor, composer.phar and composer.lock) within the project. The goal is to only load them within the running container, to not need to place them in repositories as well. When I however trigger the step debugger, as soon as I step into classes that are loaded via the autoloader, I get stuff like "Cannot find a local copy of the file on server /var/ww/html/vendor/composer/ClassLoader.php". This makes total sense, as I have no vendor folder present in the local project. Can youhowever, within IntelliJs IDE,  somehow coordinate with xdebug that it takes the files for the step debugging directly from source, like the vendor folder, only present there? Or would I need to manually install composer and download the packages to be able to fully debug the application locally? I'm really confused by how you define your mappings for the debuggings, hence my question. There is Languages & Frameworks > PHP > Servers that you can use to define Servers with path mappings, then there is also Build, Execution, Deployment > Deployment where you can define Deployment instances + concerned path mappings, but it's not clear to me if and in which measure these settings are used in debuggings??

 

These are my two questions, thanks in advance for your help!

 

评论操作 固定链接

Our apologies it took so long for us to respond.

When I go to Run > Web Server Debug Validation, and then select "Local Web Server orShared Folder", then type "C:\Users....project_abc_root" as the value of "Path to create validation script", and "http://localhost:80" as the value of "URL to validation script", I always get: "Specified URL is not reachable, caused by: 'Request failed with status code 404'". Why? Same if I specify "C:\Users....project_abc_root\php" as the value of "Path to create validation script"

According to the volume mappings in your docker-compose.yml, you map ./php/src to /var/www/html/src.
You don't the project root, nor do you map ./php, so whatever you put in there, including the validation script, doesn't make its way into the container.
Please try specifying C:\Users\....project_abc_root\php\src instead.

Please also pay attention to the validation script URL - I assume that /var/www/html is the web server's document root, so you should use http://localhost/php/src as the URL.

an youhowever, within IntelliJs IDE, somehow coordinate with xdebug that it takes the files for the step debugging directly from source, like the vendor folder, only present there?

There's no way to achieve that - you have to have all PHP files available to the IDE in order to debug them.

There is Languages & Frameworks > PHP > Servers

This is the mappings that are used for PHP debugging; the deployment ones are for uploading/downloading, they are not applicable in your case.

0

请先登录再写评论。