Skip to content

Commit

Permalink
Add simple environment-based PHP configuration
Browse files Browse the repository at this point in the history
This adds a layer of common sense on top of the other changes I've
worked on to allow easy configuration variable setting.

Fixes #166
  • Loading branch information
andrewnicols committed Mar 16, 2023
1 parent 0a88c65 commit 08592a3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ docker run \

These initialization files will be executed in sorted name order as defined by the current locale, which defaults to en_US.utf8.

## PHP Configuration

As a lightweight alternative to a full PHP configuration file, you can specify a set of prefixed environment variables when starting your container with these variables turned into ini-format configuration.

Any environment variable whose name is prefixed with `INI-` will have the prefix removed, and will be added to a new ini file before the main command starts.

```
docker run \
--name web0 \
-p 8080:80 \
-v $PWD/moodle:/var/www/html
-e INI-upload_max_filesize=200M \
-e INI-post_max_size=210M \
moodle-php-apache:latest
```

## See also
This container is part of a set of containers for Moodle development, see also:

Expand Down
4 changes: 4 additions & 0 deletions root/usr/local/bin/moodle-docker-php-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ docker_process_init_files() {
done
}

echo "Running PHP Configuration fetcher"
/usr/local/bin/moodle-docker-php-ini
echo

echo "Running entrypoint files from /docker-entrypoint.d/*"
docker_process_init_files /docker-entrypoint.d/*
echo
Expand Down
29 changes: 29 additions & 0 deletions root/usr/local/bin/moodle-docker-php-ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -e

echo "Checking for php configuration in environment"

localinifile="/usr/local/etc/php/conf.d/10-local.ini"

cat <<'EOF' > $localinifile
; --
; Automatically generated php ini configuration for Moodle
; --
EOF

env | while IFS= read -r line; do
value=${line#*=}
fullname=${line%%=*}
if [[ $fullname = INI-* ]]; then
name=`echo $fullname | sed 's/^INI-//'`
echo "=> Found '${name}' with value '${value}'"

cat << EOF >> $localinifile
; $fullname=$value
$name = $value
EOF
fi
done

0 comments on commit 08592a3

Please sign in to comment.