|
7 | 7 |
|
8 | 8 | # Controls which extensions are enabled. |
9 | 9 |
|
| 10 | +CUSTOM_INI="/usr/local/etc/php/conf.d/zz-02-custom.ini" |
| 11 | + |
10 | 12 | if [ ! -z "${PHP_EXTENSIONS}" ]; then |
11 | 13 | # If PHP_EXTENSIONS is set: only enable the ones specified |
12 | 14 |
|
@@ -84,11 +86,43 @@ if [ ! -z "${APPLICATION_UID}" ] || [ ! -z "${APPLICATION_GID}" ]; then |
84 | 86 | test -d /home/application && find /home/application/ -mount -not -user application -exec chown application: {} \; |
85 | 87 | fi |
86 | 88 |
|
| 89 | +# Start with a clean custom php.ini: |
| 90 | +rm -f "$CUSTOM_INI" |
| 91 | + |
87 | 92 | if [ ! -z "${PHP_INI_OVERRIDE}" ]; then |
88 | | - echo "${PHP_INI_OVERRIDE}" | sed -e 's/\\n/\n/g' > /usr/local/etc/php/conf.d/zz-02-custom.ini |
| 93 | + echo "${PHP_INI_OVERRIDE}" | sed -e 's/\\n/\n/g' > "$CUSTOM_INI" |
89 | 94 | fi |
90 | 95 | unset PHP_INI_OVERRIDE |
91 | 96 |
|
| 97 | +# Fill from ENV variables prefixed with PHPINI__ |
| 98 | +# Example: PHPINI__session__save_handler=redis -> session.save_handler = redis |
| 99 | +# PHPINI__redis__session__locking_enabled=1 -> redis.session.locking_enabled = 1 |
| 100 | +if env | grep -q '^PHPINI__'; then |
| 101 | + # Ensure the custom ini exists (and keep any content already written above) |
| 102 | + touch "$CUSTOM_INI" |
| 103 | + # Iterate over all matching env var names only |
| 104 | + for name in $(printenv | awk -F= '/^PHPINI__/ {print $1}'); do |
| 105 | + value=$(printenv "$name") |
| 106 | + # Transform key: PHPINI__this__setting => this.setting |
| 107 | + key=${name#PHPINI__} |
| 108 | + key=$(printf '%s' "$key" | sed 's/__/./g') |
| 109 | + key=$(printf '%s' "$key" | tr '[:upper:]' '[:lower:]') |
| 110 | + # Append as "key = value" (value is written as-is; quote in ENV if needed) |
| 111 | + printf '* Setting in php.ini: %s = %s\n' "$key" "$value" |
| 112 | + printf '%s = %s\n' "$key" "$value" >> "$CUSTOM_INI" |
| 113 | + # Unset them, not relevant to the running containers |
| 114 | + unset "$name" |
| 115 | + done |
| 116 | +fi |
| 117 | + |
| 118 | +if [ -s "$CUSTOM_INI" ] |
| 119 | +then |
| 120 | + echo "* Custom php.ini settings ($CUSTOM_INI)" |
| 121 | + echo "- - - 8< - - -" |
| 122 | + cat $CUSTOM_INI |
| 123 | + echo "- - - 8< - - -" |
| 124 | +fi |
| 125 | + |
92 | 126 | # Remove ENV variables that are meant only for the SSH container |
93 | 127 |
|
94 | 128 | unset SSH_PRIVATE_KEY |
|
0 commit comments