Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #19178 > unrolled thread

[docker] error_log() not work

Started bySupaPlex <old@gamer.s>
First post2022-11-26 12:18 +0100
Last post2022-11-29 21:22 +0100
Articles 7 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  [docker] error_log() not work SupaPlex <old@gamer.s> - 2022-11-26 12:18 +0100
    Re: [docker] error_log() not work "J.O. Aho" <user@example.net> - 2022-11-26 13:28 +0100
      Re: [docker] error_log() not work SupaPlex <old@gamer.s> - 2022-11-26 15:45 +0100
        Re: [docker] error_log() not work SupaPlex <old@gamer.s> - 2022-11-26 16:48 +0100
          Re: [docker] error_log() not work Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-11-26 16:52 +0000
            Re: [docker] error_log() not work SupaPlex <old@gamer.s> - 2022-11-26 21:33 +0100
              Re: [docker] error_log() not work Arno Welzel <usenet@arnowelzel.de> - 2022-11-29 21:22 +0100

#19178 — [docker] error_log() not work

FromSupaPlex <old@gamer.s>
Date2022-11-26 12:18 +0100
Subject[docker] error_log() not work
Message-ID<tlssmh$1kur$1@gioia.aioe.org>
$ 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?

-----BEGIN PGP MESSAGE-----

hQGMAyHa6HqE1N3qAQv+LshhnqeyR4QoIyyuSKO0K7FlB1CiB6m9p7UwoiZzbhcl
l0bvq71ZwqXxnhsmB1NLD6Asxt/oOSEq/jMKOmYMTQrPxJmFZ4kgj2VjKzvYYghE
GtPD4lLTVLANvq39vzLCiW0Xqi7qUSRHOUeeRDiwmUxte3hRQxAHq5W5rA2frdWz
jrVrdgIWFztYOuuhwoQJ8EUSxSQ9vDpwTfg8AB+RtjbhEnKjQcbXLoq8ab64+/4G
L4p98rc8kTSPL/9EKm/g1kjXXUk+R8wTCxSYxI2PsQ8YNbpv9ECyVX1ndZzbFgV5
G8VEQcTRsZ3G8K2BnVIVbb08YxmqtqnFteGWULwMC7X/vvlozrmhRi1cf9wjNJCB
dgA/PEA2jxPPyHyFpsA1oxD1bxgiuxCMLlp+6XGCLioTDYidtV91g1WleQS+Vn1j
dYKBNzCPaGPpg1gW305v26q0cRwcvxgzKBFDI1/oq1DFYERLmA/KWKw/9+An9C1a
g/y/wHvEE4m/b96P/9fL0n8BncWPV00QAGihEa1LU5Vt8O8pWA9BulAQGG+RzxUb
0hwcOpR+BQ8kwq08fHDc2FB2QLM3g5adR5UpAq4Nlow9uO1AkRfbO8Lq14sDErCG
zmoKkEansQ2AQSLoo6Cirb+CmsqnxsE71SJICDsh9EPazXIZq+qFPStq+7vCPPtv
=bZWC
-----END PGP MESSAGE-----

[toc] | [next] | [standalone]


#19179

From"J.O. Aho" <user@example.net>
Date2022-11-26 13:28 +0100
Message-ID<juef46Fr2ohU1@mid.individual.net>
In reply to#19178
On 26/11/2022 12.18, SupaPlex wrote:

> $ 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'),
> );

> $ 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?

Does the /var/log directory exist?
Does the user which runs the process have the right to write into the 
directory?

-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#19180

FromSupaPlex <old@gamer.s>
Date2022-11-26 15:45 +0100
Message-ID<tlt8qq$ll3$2@gioia.aioe.org>
In reply to#19179
Il 26/11/22 13:28, J.O. Aho ha scritto:
> On 26/11/2022 12.18, SupaPlex wrote:
> 
>> $ 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'),
>> );
> 
>> $ 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?
> 
> Does the /var/log directory exist?
> Does the user which runs the process have the right to write into the 
> directory?
> 

$ docker run xxx ls -ld /var/log
drwxr-xr-x 1 root root 4096 Aug 23 13:04 /var/log

[toc] | [prev] | [next] | [standalone]


#19181

FromSupaPlex <old@gamer.s>
Date2022-11-26 16:48 +0100
Message-ID<tltcg8$93m$1@gioia.aioe.org>
In reply to#19180
Il 26/11/22 15:45, SupaPlex ha scritto:
> 
> $ docker run xxx ls -ld /var/log
> drwxr-xr-x 1 root root 4096 Aug 23 13:04 /var/log

Furthermore

file_put_contents('/var/log/error.log', 123);

Output

file_put_contents(/var/log/error.log): Failed to open stream: Permission 
denied

[toc] | [prev] | [next] | [standalone]


#19182

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2022-11-26 16:52 +0000
Message-ID<tltg9b$1d0sk$1@dont-email.me>
In reply to#19181
On Sat, 26 Nov 2022 16:48:24 +0100, SupaPlex wrote:

> Il 26/11/22 15:45, SupaPlex ha scritto:
>> 
>> $ docker run xxx ls -ld /var/log drwxr-xr-x 1 root root 4096 Aug 23
>> 13:04 /var/log
> 
> Furthermore
> 
> file_put_contents('/var/log/error.log', 123);
> 
> Output
> 
> file_put_contents(/var/log/error.log): Failed to open stream: Permission
> denied

Not surprising, as, in your case, only root can create files in the /var/
log directory and the php process that attempts to file_put_contents() 
to /var/log/error.log does not likely run as root.

 Your ls listing shows
  /var/log drwxr-xr-x 1 root root
which means that only processes run with effective userid of root can
update the directory with new or changed directory entries. That means
that /only root/ can create /var/log/error.log



To fix the problem, either change the permissions of /var/log to
permit your php process to write to it, or run your php process as root.

HTH
-- 
Lew Pitcher
"In Skills, We Trust"

[toc] | [prev] | [next] | [standalone]


#19184

FromSupaPlex <old@gamer.s>
Date2022-11-26 21:33 +0100
Message-ID<tltt68$1t5m$2@gioia.aioe.org>
In reply to#19182
Il 26/11/22 17:52, Lew Pitcher ha scritto:
> ...

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

Problem solved!!!

Since we're here, you can reply to the thread
[docker] error_log() not write inside web page

[toc] | [prev] | [next] | [standalone]


#19186

FromArno Welzel <usenet@arnowelzel.de>
Date2022-11-29 21:22 +0100
Message-ID<jun801Ftd3rU5@mid.individual.net>
In reply to#19184
SupaPlex, 2022-11-26 21:33:

> Il 26/11/22 17:52, Lew Pitcher ha scritto:
>> ...
> 
> # chown www-data:www-data /var/log/error.log
> 
> Problem solved!!!
> 
> Since we're here, you can reply to the thread
> [docker] error_log() not write inside web page

Please first try to understand the very basics of how to use Docker and
how PHP works in general before asking stuff here.

Also there is a very extensive documentation available:

<https://www.php.net/docs.php>

<https://docs.docker.com>


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web