2

I found an issue in my dev container that when I leave the Xdebug helper browser extension in debug mode, while my Xdebug server is actually not running, then multiple error log files are created.

I started to simplify the container, and it turned out that the issue is present even with a fresh Laravel install. I don't know whether this is a bug in PHP, Xdebug, Apache or Laravel.

My Dockerfile is:

FROM php:8.1-apache

RUN apt-get update && apt-get install -y curl unzip

RUN cd /tmp && curl -sS https://getcomposer.org/installer | php && \
    mv composer.phar /usr/local/bin/composer

RUN pecl install xdebug && docker-php-ext-enable xdebug

RUN echo "error_log = my_error_log" >> $PHP_INI_DIR/conf.d/php.ini && \
    echo "xdebug.mode = debug" >> $PHP_INI_DIR/conf.d/php.ini && \
    echo "xdebug.client_host = localhost" >> $PHP_INI_DIR/conf.d/php.ini

RUN sed -i 's#DocumentRoot .*#DocumentRoot /var/www/html/public#' /etc/apache2/sites-available/000-default.conf

ENV HOME /var/www
RUN chmod 777 $HOME

USER www-data

WORKDIR /var/www
RUN composer create-project laravel/laravel html

My docker-compose.yml file is:

version: "3"
services:
  example:
    container_name: example
    build: .

After I compose up this project, I made exactly one HTTP request:

$ docker compose exec example curl --head --cookie "XDEBUG_SESSION=random_stuff" localhost
HTTP/1.1 200 OK
Date: Sat, 28 Jan 2023 13:28:42 GMT
Server: Apache/2.4.54 (Debian)
X-Powered-By: PHP/8.1.14
Cache-Control: no-cache, private
Set-Cookie: XSRF-TOKEN=eyJpdiI6IlV0ZnBBYjh1VCtIaUdHMlF2TG52bXc9PSIsInZhbHVlIjoiei9TUUVCL29VeW82aHg5R1NNRm5LMmhKdEJlR2lYSDNic0M3d1F4K2gyeG05TThueG1zWHA0ai94b1E0UVpJeW5aemUxUTh5UEJtbkFDUnZ4SnhUZ0lkb2lxQnl0S0lGRDByQUtJSjdQOXA4YVhGTnNaK3ZDU3duZVBDbnFWNEwiLCJtYWMiOiJhOGViZTI2ODdlMzRiY2QzNDhkNzQwZDhiNWU0NTgzNmVlOTczNjBmNjJlMWQ1ODliOWZjYjZmY2U1OWY2M2Y3IiwidGFnIjoiIn0%3D; expires=Sat, 28 Jan 2023 15:28:42 GMT; Max-Age=7200; path=/; samesite=lax
Set-Cookie: laravel_session=eyJpdiI6IlJ5MVpaVVduZGdDbnZsMTA2QWpjNlE9PSIsInZhbHVlIjoibDhoMm1oa2U1MlgraFlFQjVyVWQ5Z0dSR0Z4QSsyckhXTjVvVUs4SGRlc3JtVDRTVUc2eXY1THkzbDgyMGJrL3UyN3Q2RFlkU2FQUVZxa1dEdThFZ3owVWZTUGlHWFlYd2NJR3dVQXNjMDhheUxVRXJPRFRPemY5UkszWFdCeFIiLCJtYWMiOiJjZTVjZjg0NDE4ODFkZTI3NWRlNWNjYTEzZTc5NGU5MjEyYmQ5YzdhZDUxZTNhNmNjMWE3OTM0NmQ1MDc4OGIwIiwidGFnIjoiIn0%3D; expires=Sat, 28 Jan 2023 15:28:42 GMT; Max-Age=7200; path=/; httponly; samesite=lax
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8

but multiple error logs are created:

$ docker compose exec example cat /var/www/my_error_log
[28-Jan-2023 13:28:42 UTC] Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).

$ docker compose exec example cat /var/www/html/public/my_error_log
[28-Jan-2023 13:28:42 UTC] Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).

I know it may be a bad practice to use relative path in error_log directive. When I use absolute path, obviously only one file will be created but with twice the error message.

So why my PHP creates multiple error logs?

What I tried:

  • use an older version of xdebug, starting from 3.0.0,
  • use PHP 7.3, 8.0, 8.1 and 8.2 images (xdebug-3.1.6 is the latest version supports PHP 7.3),
  • use the --no-dev option with Composer,
  • use older version of Laravel, but the issue is present even in v6 branch.
pistvan
  • 21
  • 1
  • If that request would be done in a browser, I would think about a missing resource (like `favicon.ico` -- the most common case). But for `curl` request where it is just the request itself (when nobody parses it to request additional resources)... I'm not sure what that might be. Maybe your code (one of the components) makes a sub-request? – LazyOne Jan 28 '23 at 17:46
  • I suggest you make some test file, place it in the website root (`/var/www/html/public/mytest.php`) and call it via curl -- will you see 2 entries again? If not -- this has to be your framework (Laravel) or one of the used packages. If yes -- look at the web server config. – LazyOne Jan 28 '23 at 17:47
  • P.S. As a side note: https://stackoverflow.com/a/65264131/783119 -- you can try suppressing Xdebug logging completely (but I'm not sure if that will actually work TBH) – LazyOne Jan 28 '23 at 17:49
  • I know this is not related, but when you run the composer install (get composer from URL), use this instead `COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer` and that's it, composer installed – matiaslauriti Jan 28 '23 at 19:10

0 Answers0