Skip to content

Commit 4ffc899

Browse files
committed
WIP: Allow specification of DocumentRoot with intelligent fallback
1 parent 8ced11e commit 4ffc899

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \
4646

4747
ADD root/usr /usr
4848
ADD root/etc /etc
49+
ADD root/system-docker-entrypoint.d/wwwroot.sh /system-docker-entrypoint.d/10-wwwroot.sh
4950

5051
# Fix the original permissions of /tmp, the PHP default upload tmp dir.
5152
RUN chmod 777 /tmp && chmod +t /tmp
5253

54+
# Allow configuration of the Apache DocumentRoot via environment variable.
55+
# Note: Do not specify a default value here, as it will be set in the
56+
# `wwwroot.sh` script, which will be run before the Apache server starts.
57+
# This allows the user to override the default value by setting the
58+
# `APACHE_DOCUMENT_ROOT` environment variable when running the container.
59+
60+
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
61+
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
62+
5363
CMD ["apache2-foreground"]
5464
ENTRYPOINT ["moodle-docker-php-entrypoint"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $ docker run --name web0 -p 8080:80 -v $PWD:/var/www/html moodlehq/moodle-php-a
4141

4242
## Features
4343
* Preconfigured with all php extensions required for Moodle development and all database drivers
44-
* Serves wwwroot configured at /var/www/html/
44+
* Serves using the `APACHE_DOCUMENT_ROOT` environment variable for the`DocumentRoot`, with a default value of`/var/www/html/`
4545
* For PHP 7.3 and up, both `linux/amd64` and `linux/arm64` images are being built. Note that `linux/arm64` doesn't support the sqlsrv and oci extensions yet. Other than that, both architectures work exactly the same.
4646
* Verified by [automated tests](https://travis-ci.com/moodlehq/moodle-php-apache).
4747
* Autobuilt from GHA, on push.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
echo
2+
echo "#######################################"
3+
echo "# moodle-php-apache wwwroot setup"
4+
echo "#######################################"
5+
echo "#"
6+
echo "# Setting up Apache DocumentRoot"
7+
8+
if [ -z "$APACHE_DOCUMENT_ROOT" ]; then
9+
echo "# No value set for \$APACHE_DOCUMENT_ROOT. Creating default value."
10+
export APACHE_DOCUMENT_ROOT=/var/www/html
11+
12+
if [ -d "$APACHE_DOCUMENT_ROOT/public" ]; then
13+
echo "# Detected /public directory."
14+
echo "# Using /var/www/html/public"
15+
export APACHE_DOCUMENT_ROOT="$APACHE_DOCUMENT_ROOT/public"
16+
else
17+
echo "# Using default Apache DocumentRoot: /var/www/html"
18+
fi
19+
20+
else
21+
echo "# A value was provided as an environment variable"
22+
fi
23+
24+
echo "# \$APACHE_DOCUMENT_ROOT: $APACHE_DOCUMENT_ROOT"
25+
echo "#"
26+
echo "#######################################"
27+
echo

root/usr/local/bin/moodle-docker-php-entrypoint

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ echo "Running PHP Configuration fetcher"
3131
/usr/local/bin/moodle-docker-php-ini
3232
echo
3333

34-
echo "Running entrypoint files from /docker-entrypoint.d/*"
35-
docker_process_init_files /docker-entrypoint.d/*
34+
mkdir -p /system-docker-entrypoint.d /docker-entrypoint.d /final-docker-entrypoint.d
35+
echo "Building Entrypoint files from /system-docker-entrypoint.d/* and /docker-entrypoint.d/*"
36+
37+
echo "Copying /system-docker-entrypoint.d/* to /final-docker-entrypoint.d/"
38+
cp -rf /system-docker-entrypoint.d/* /final-docker-entrypoint.d/ || true
39+
echo "Copying /docker-entrypoint.d/* to /final-docker-entrypoint.d/"
40+
cp -rf /docker-entrypoint.d/* /final-docker-entrypoint.d/ || true
41+
42+
echo "Running entrypoint files from /final-docker-entrypoint.d/*"
43+
docker_process_init_files /final-docker-entrypoint.d/*
3644
echo
3745

3846
echo "Starting docker-php-entrypoint with $@"

0 commit comments

Comments
 (0)