Skip to content

Commit

Permalink
Disable PHP notices on production envs by default (#1162)
Browse files Browse the repository at this point in the history
Adding logic for the php containers to disable notices by default on production.
  • Loading branch information
cdchris12 authored and Schnitzel committed Sep 8, 2019
1 parent 61904b3 commit 523eb27
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
25 changes: 13 additions & 12 deletions docs/using_lagoon/docker_images/php-fpm.md
Expand Up @@ -51,20 +51,21 @@ Environment variables are meant to do common behavior changes of php.

| Environment Variable | Default | Description |
| --------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `PHP_MAX_EXECUTION_TIME` | `900` | Maximum execution time of each script, in seconds, [see php.net](http://php.net/max-execution-time) |
| `PHP_MAX_INPUT_VARS` | `2000` | How many input variables will be accepted, [see php.net](http://php.net/manual/en/info.configuration.php#ini.max-input-vars)
| `PHP_MAX_FILE_UPLOADS` | `20` | The maximum number of files allowed to be uploaded simultaneously, [see php.net](http://php.net/manual/en/ini.core.php#ini.max-file-uploads)|
| `PHP_MEMORY_LIMIT` | `400M` | Maximum amount of memory a script may consume, [see php.net](http://php.net/memory-limit) |
| `NEWRELIC_ENABLED` | `false` | Enable NewRelic performance monitoring, needs`NEWRELIC_LICENSE` be configured |
| `NEWRELIC_LICENSE` | (not set) | NewRelic License to be used, Important: `NEWRELIC_ENABLED` needs to be set to `true` in order for NewRelic to be enabled
| `PHP_APC_ENABLED` | `1` | Can be set to 0 to disable APC, [see php.net](http://php.net/manual/en/apc.configuration.php#ini.apc.enabled) |
| `PHP_APC_SHM_SIZE` | `32m` | The size of each shared memory segment given, [see php.net](http://php.net/manual/en/apc.configuration.php#ini.apc.shm-size) |
| `PHP_DISPLAY_ERRORS` | `Off` | This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user, [see php.net](http://php.net/display-errors) |
| `PHP_DISPLAY_STARTUP_ERRORS` | `Off` | Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep it off, except for debugging., [see php.net](http://php.net/display-startup-errors) |
| `PHP_APC_SHM_SIZE` | `32m` | The size of each shared memory segment given, [see php.net](http://php.net/manual/en/apc.configuration.php#ini.apc.shm-size) |
| `PHP_APC_ENABLED` | `1` | Can be set to 0 to disable APC, [see php.net](http://php.net/manual/en/apc.configuration.php#ini.apc.enabled) |
| `XDEBUG_ENABLED` | (not set) | Used to enable xdebug extension, [see php.net](http://php.net/manual/en/apc.configuration.php#ini.apc.enabled) |
| `PHP_ERROR_REPORTING` | Production: `E_ALL & ~E_DEPRECATED & ~E_STRICT`<br> Development: `E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE` | The desired logging level you'd like PHP to use. [see php.net](https://www.php.net/manual/en/function.error-reporting.php) |
| `PHP_FPM_PM_MAX_CHILDREN` | `50` | The the maximum number of child processes [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_FPM_PM_START_SERVERS` | `2` | The number of child processes created on startup. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_FPM_PM_MIN_SPARE_SERVERS` | `2` | The desired minimum number of idle server processes. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_FPM_PM_MAX_REQUESTS` | `500` | The number of requests each child process should execute before respawning. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) | |
| `PHP_FPM_PM_MAX_SPARE_SERVERS` | `2` | The desired maximum number of idle server processes. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_FPM_PM_MIN_SPARE_SERVERS` | `2` | The desired minimum number of idle server processes. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_FPM_PM_PROCESS_IDLE_TIMEOUT` | `60s` | The number of seconds after which an idle process will be killed. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_FPM_PM_MAX_REQUESTS` | `500` | The number of requests each child process should execute before respawning. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `NEWRELIC_ENABLED` | `false` | Enable NewRelic performance monitoring, needs`NEWRELIC_LICENSE` be configured |
| `NEWRELIC_LICENSE` | (not set) | NewRelic License to be used, Important: `NEWRELIC_ENABLED` needs to be set to `true` in order for NewRelic to be enabled |
| `PHP_FPM_PM_START_SERVERS` | `2` | The number of child processes created on startup. [see php.net](http://php.net/manual/en/install.fpm.configuration.php) |
| `PHP_MAX_EXECUTION_TIME` | `900` | Maximum execution time of each script, in seconds, [see php.net](http://php.net/max-execution-time) |
| `PHP_MAX_FILE_UPLOADS` | `20` | The maximum number of files allowed to be uploaded simultaneously, [see php.net](http://php.net/manual/en/ini.core.php#ini.max-file-uploads)|
| `PHP_MAX_INPUT_VARS` | `2000` | How many input variables will be accepted, [see php.net](http://php.net/manual/en/info.configuration.php#ini.max-input-vars)
| `PHP_MEMORY_LIMIT` | `400M` | Maximum amount of memory a script may consume, [see php.net](http://php.net/memory-limit) |
| `XDEBUG_ENABLED` | (not set) | Used to enable xdebug extension, [see php.net](http://php.net/manual/en/apc.configuration.php#ini.apc.enabled) |
10 changes: 10 additions & 0 deletions docs/using_lagoon/environment_variables.md
Expand Up @@ -78,3 +78,13 @@ If you want to define environment variables different per environment you can cr
### `.env` and `.env.defaults`
`.env` and `.env.defaults` will act as the default values for environment variables if none other is defined. For example
as default environment variables for Pull-Request environments (see [Worfklows](./workflows.md#pull-requests)).

## Special Environment Variables

### `PHP_ERROR_REPORTING`

This variable, if set, will define the logging level you would like PHP to use. If not supplied, it will be set dynamically based on whether this is a production or development environment.

On production environments, this value defaults to `E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE`

On development environments, this value defaults to `E_ALL & ~E_DEPRECATED & ~E_STRICT`
1 change: 1 addition & 0 deletions images/php/fpm/00-lagoon-php.ini.tpl
Expand Up @@ -7,6 +7,7 @@ display_errors = ${PHP_DISPLAY_ERRORS:-Off}
display_startup_errors = ${PHP_DISPLAY_STARTUP_ERRORS:-Off}
auto_prepend_file = ${PHP_AUTO_PREPEND_FILE:-none}
auto_append_file = ${PHP_AUTO_APPEND_FILE:-none}
error_reporting = ${PHP_ERROR_REPORTING:-E_ALL & ~E_DEPRECATED & ~E_STRICT}

[APC]
apc.shm_size = ${PHP_APC_SHM_SIZE:-32m}
Expand Down
7 changes: 7 additions & 0 deletions images/php/fpm/entrypoints/51-production-detection.sh
@@ -0,0 +1,7 @@
#!/bin/sh

if [[ -z "${PHP_ERROR_REPORTING}" ]]; then
if [[ ${LAGOON_ENVIRONMENT_TYPE} == "production" ]]; then
export PHP_ERROR_REPORTING="E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE"
fi
fi
4 changes: 2 additions & 2 deletions images/php/fpm/php.ini
Expand Up @@ -261,8 +261,8 @@ memory_limit = 400M
; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; Development Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
; http://php.net/error-reporting
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

Expand Down

0 comments on commit 523eb27

Please sign in to comment.