Skip to content

PHP parse errors not logged due to error_reporting value #420

Closed
@ptrdlbrg

Description

@ptrdlbrg

What happened vs what I expected

I ran WordPress based on the wordpress:5.2.2-php7.3-apache image. I updated a page template and visited the page in a browser. I got an HTTP 500 "Internal Server Error". I expected to be able to see the error as logged to the Apache error log, which for this image goes to the docker log. There was no error in the log.

Why

It turns out that the HTTP 500 error was caused by a PHP parse error. Parse errors aren't included in the error logging because of this entry in /usr/local/etc/php/conf.d/error-logging.ini:
error_reporting = 4339

That integer value has a 0 in the bit for reporting parse errors. It would need to be changed to 4343 in order to have PHP parse errors included in the error log. Changing error_reporting to 4343 and restarting made it so that I could see the parse errors in the logs. Ideally this value wouldn't be set as a number at all, since PHP supports using expressions. The following value is in php.ini-production and might be a better choice: E_ALL & ~E_DEPRECATED & ~E_STRICT

Problems

I see a few problems with the current situation.

  1. The error_reporting value in /usr/local/etc/php/conf.d/error-logging.ini is a number. It should be an expression so it is easier to read.
  2. The error_reporting value in /usr/local/etc/php/conf.d/error-logging.ini doesn't include parse errors. I can't think of a reason why you would want to exclude parse errors.
  3. If I copy php.ini-production to php.ini, which is recommended for a production site, then the error_reporting value is set in two places, and the one from php.ini is overridden by error-logging.ini. I did not expect this and it was hard for me to hunt down. I assume others may have the same problem.

Steps to reproduce

mkdir missing_parse_error
cd missing_parse_error
# create Docker file from the wordpress image
cat > Dockerfile <<'EOF'
FROM wordpress:5.2.2-php7.3-apache
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN echo "this line causes an intentional parse error" >> /usr/src/wordpress/index.php
EOF

#create docker-compose file
cat > docker-compose.yml <<'EOF'
version: '3'
services:
  wordpress:
    build: "."
    ports:
     - "80:80"
    environment:
      WORDPRESS_DB_HOST: "mysql"
      WORDPRESS_DB_USER: "root"
      WORDPRESS_DB_PASSWORD: "password"
      WORDPRESS_DB_NAME: "wordpress"
  mysql:
    image: "mysql/mysql-server:5.7.27"
    environment:
      MYSQL_ROOT_HOST: "%"
      MYSQL_ROOT_PASSWORD: "password"
EOF
docker-compose build
docker-compose up -d
#run a request that will trigger a 500 error (You may have to wait while the containers start)
curl -v http://127.0.0.1
# output the logs and see that there is no parse error logged
docker-compose logs wordpress

#update the Dockerfile to add a different value in error-logging.ini
cat >> Dockerfile <<'EOF'
RUN sed -i -e 's/^error_reporting .*/error_reporting = E_ALL \& ~E_DEPRECATED \& ~E_STRICT/' /usr/local/etc/php/conf.d/error-logging.ini
EOF
docker-compose build
docker-compose up -d
#run a request that will trigger a 500 error 
curl -v http://127.0.0.1
# output the logs and see that there is a parse error now
docker-compose logs wordpress

Possible solutions

  1. Change the error-logging.ini value to 4343 so parse errors are logged
  2. Change the error-logging.ini value so it includes parser errors and is also readable, such as E_ALL & ~E_DEPRECATED & ~E_STRICT
  3. Rearrange the configuration such that the value of error_reporting in php.ini isn't overridden. This may involve having a default php.ini.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions