Jump to content

[docker] error_log() not work


rick645
Go to solution Solved by gizmola,

Recommended Posts

$ cat master/.htaccess 
RewriteEngine On
RewriteRule ^(.*)$ src/index-debug.php [L]

$ cat docker-compose.yml 
services:
    web:
        build: .
        ports:
            - 8014:80
        volumes:
            - .:/var/www/html
            - ./docker/volumes/etc/php.ini:/usr/local/etc/php/php.ini

$ cat Dockerfile 
FROM php:apache
RUN a2enmod rewrite

$ cat master/src/index-debug.php 
<?php
error_log("error message 123");
var_dump(
    ini_get('error_log'),
    ini_get('log_errors'),
    file_get_contents('/var/log/error.log'),
);

$ cat docker/volumes/etc/php.ini 
log_errors = On
error_log = /var/log/error.log

$ docker-compose up -d
WARNING: Found orphan containers (xxx) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Starting xxx... done

$ curl http://localhost:8014/master/src/index-debug.php
string(18) "/var/log/error.log"
string(1) "1"
<b>Warning</b>:  file_get_contents(/var/log/error.log): Failed to open stream: No such file or directory in <b>/var/www/html/master/src/index-debug.php</b> on line <b>4</b><br />
bool(false)

Why?

Edited by rick645
Link to comment
Share on other sites

On 11/26/2022 at 10:06 PM, gizmola said:

The PHP process may not be able to write to the /var/log directory.  Assuming it's the apache user that php is running as in this case.  Connect to the container and check out the perms for /var/log.  

$ chown www-data:www-data /var/log/error.log

Solved!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.