• [docker] error_log() not work

    From SupaPlex@21:1/5 to All on Sat Nov 26 12:18:41 2022
    $ 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-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to SupaPlex on Sat Nov 26 13:28:54 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SupaPlex@21:1/5 to All on Sat Nov 26 15:45:46 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SupaPlex@21:1/5 to All on Sat Nov 26 16:48:24 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to SupaPlex on Sat Nov 26 16:52:59 2022
    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"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SupaPlex@21:1/5 to All on Sat Nov 26 21:33:12 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Tue Nov 29 21:22:25 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)