Skip to content

Commit 11bf799

Browse files
committed
wip
1 parent 8ced11e commit 11bf799

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
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/docker-entrypoint.d/wwwroot.sh /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

0 commit comments

Comments
 (0)