Skip to content

Add apache support #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ENV ENABLE_GCP="${ENABLE_GCP:-0}" \
# ssmtp: synchronouse mailer, very handy in CLI scripts on docker
ENV PATH="${PATH}:${WORKDIR}/docker/bin" \
BUILD_PACKAGES="ccache build-essential unzip" \
SYSTEM_PACKAGES="ssmtp busybox-static netcat vim less tree libtcmalloc-minimal4 git postgresql-client gettext nginx" \
SYSTEM_PACKAGES="ssmtp busybox-static netcat vim less tree libtcmalloc-minimal4 git postgresql-client gettext nginx apache2" \
JESSIE_PACKAGE_MAP="libpng16-16:libpng12-0 libicu57:libicu52 libmagickwand-6.q16-3:libmagickwand-6.q16-2 libmagickcore-6.q16-3:libmagickcore-6.q16-2 npm:" \
ENABLE_NEWRELIC="false"

Expand All @@ -45,6 +45,16 @@ ENV NGINX_SITES_AVAILABLE="/etc/nginx/sites-available" \
COMPRESS_FILE_MATCH="^.*\.(css|js|xml|csv|txt|md|html)\$" \
COMPRESS_FILE_PATHS="public"

# APACHE
ENV APACHE_SITES_AVAILABLE="/etc/apache2/sites-available" \
APACHE_SITES_ENABLED="/etc/apache2/sites-enabled" \
APACHE_DIRECTORY_INDEX="index.html index.php" \
APACHE_OVERRIDE="none" \
APACHE_MODS_ENABLE="rewrite headers" \
PHPFPM_HOST="127.0.0.1" \
PHPFPM_PORT="9000" \
DOCUMENT_ROOT="${WORKDIR}/public"

# NODEJS
ENV ENABLE_NODEJS="true" \
NODEJS_VERSION="8" \
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ Nginx does not support environment variables by itself (except if you enable the
| COMPRESS_FILE_MATCH | Extended regex for matching files which should be compressed for nginx |
| COMPRESS_FILE_PATHS | Where to look for files to be compressed during build time |

### Apache2
| Name | Description |
|------------------------|------------------------------------------------------------------------|
| APACHE_SITES_AVAILABLE | Path to the `sites-available/` directory |
| APACHE_SITES_ENABLED. | Path to the `sites-enabled/` directory |
| APACHE_DIRECTORY_INDEX | Apaceh Index Conditions |
| APACHE_OVERRIDE | Apache Override Conditions |
| APACHE_MODS_ENABLE | Apache Modules Enabled to run time |
| PHPFPM_HOST | IP/Domain where to find the php-fpm fastcgi service |
| PHPFPM_PORT | Port of the php-fpm fastcgi service |
| DOCUMENT_ROOT | Default document root for the default vhost |

### NodeJS

Expand Down
17 changes: 17 additions & 0 deletions docker/build.d/base/111_apache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

sectionText "Remove unused Apache configs comming from APT"
rm -f /etc/apache2/conf-enabled/other-vhosts-access-log.conf
rm -f /etc/apache2/conf-available/other-vhosts-access-log.conf
rm -f /var/log/apache2/other_vhosts_access.log
rm -f /etc/apache2/sites-enabled/000-default.conf
rm -f /etc/apache2/sites-available/000-default.conf
rm -f /etc/apache2/sites-available/default-ssl.conf

sectionText "Enable default used Apache Modules"
ln -fs /etc/apache2/mods-available/proxy.* /etc/apache2/mods-enabled/
ln -fs /etc/apache2/mods-available/proxy_fcgi.* /etc/apache2/mods-enabled/

sectionText "Prepare access/error log to send to stdout/stderr"
ln -sf /dev/stdout /var/log/apache2/access.log
ln -sf /dev/stderr /var/log/apache2/error.log
10 changes: 10 additions & 0 deletions docker/common.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ enable_nginx_vhost() {
envsubst '$DOCUMENT_ROOT $PHPFPM_HOST $PHPFPM_PORT $ASSET_BUCKET_NAME' > /etc/nginx/sites-enabled/${1}.conf < /etc/nginx/sites-available/${1}.conf
}

enable_apache2_vhost() {
if [ ! -e $APACHE_SITES_AVAILABLE/$1.conf ]; then
errorText "\t Apache vhost '$1' not found! Can't enable vhost!"
exit 1
fi

sectionText "Enable Apache vhost $1"
ln -sf /etc/apache2/sites-available/${1}.conf /etc/apache2/sites-enabled/${1}.conf
}

npm_install() {
local npm_dir="$1"; shift

Expand Down
15 changes: 15 additions & 0 deletions docker/etc/apache2/conf-available/security.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Directory />
AllowOverride none
Options -Indexes -Multiviews -Includes -ExecCGI
Require all denied
<LimitExcept POST GET>
Require valid-user
</LimitExcept>
</Directory>
<Files ~ "^\.">
Require all denied
</Files>
ServerTokens Prod
ServerSignature Off
TraceEnable Off
LimitRequestBody 20971520
12 changes: 12 additions & 0 deletions docker/etc/apache2/sites-available/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot ${DOCUMENT_ROOT}/
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://${PHPFPM_HOST}:${PHPFPM_PORT}${DOCUMENT_ROOT}/$1
<Directory "${DOCUMENT_ROOT}/">
DirectoryIndex ${APACHE_DIRECTORY_INDEX}
Require all granted
AllowOverride ${APACHE_OVERRIDE}
</Directory>
CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined
</VirtualHost>
10 changes: 10 additions & 0 deletions docker/shared_steps/install_php_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ php_install_gd() {
eatmydata docker-php-ext-install -j$COMPILE_JOBS $ext
}

php_install_ldap() {
local php_version=$($PHP --version | head -n1 | cut -d " " -f 2 | cut -d . -f 1,2)
if [ $php_version = "7.0" ]; then
install_packages --build "libldb-dev"
ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so
fi
sectionText "Use core install"
eatmydata docker-php-ext-install -j$COMPILE_JOBS $ext &>> $BUILD_LOG
}

php_install_extensions() {
local extensions="$*"
install_packages --build $PHP_BUILD_PACKAGES
Expand Down
3 changes: 3 additions & 0 deletions docker/start.d/apache2/200_enable_apache_vhost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

enable_apache2_vhost ${SUBSECTION_ARGS:-default}
15 changes: 15 additions & 0 deletions docker/start.d/apache2/201_enable_apache_modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

if [ -z "$APACHE_MODS_ENABLE" ]; then
sectionText "SKIP: no Modules given"
return 0
fi

apache2_enable_modules() {
local modules="$*"
for mod in $modules; do
ln -sf /etc/apache2/mods-available/$mod.* /etc/apache2/mods-enabled/
done
}

apache2_enable_modules $APACHE_MODS_ENABLE
4 changes: 4 additions & 0 deletions docker/start.d/apache2/599_start_apache2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

# start apache2 in foreground to print to stdout
/usr/sbin/apachectl -DFOREGROUND
1 change: 1 addition & 0 deletions docker/start.d/apache2/META
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SECTION_DESCRIPTION="Starts Apache2 in foreground, logging to stdout/stderr"