[bitnami/drupal] Release 10.0.1-debian-11-r0 (#20875)

Signed-off-by: Bitnami Containers <bitnami-bot@vmware.com>

Signed-off-by: Bitnami Containers <bitnami-bot@vmware.com>
This commit is contained in:
Bitnami Bot
2023-01-18 16:51:32 +01:00
committed by GitHub
parent 8390c74377
commit 535a4e34ab
73 changed files with 7027 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICqDCCAZACCQCz8T3726LYsjANBgkqhkiG9w0BAQUFADAWMRQwEgYDVQQDDAtl
eGFtcGxlLmNvbTAeFw0xMjExMTQxMTE4MjdaFw0yMjExMTIxMTE4MjdaMBYxFDAS
BgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
AQEA5NHl5TfZtO6zugau2tp5mWIcQYJhuwKTmYeXDLYAGJpoD2SixwPL5c8glneI
Rz1N2EQIZVeaWGbS0FLFlPdOkCkplpW9isYVC4XqKrk5b4HW4+YC+Cup0k+Kd4NM
eZOTUvWr5N6dIpdibkVumBc/pao8VtdwywlCL/PwGRsQtkXrRICzdtRa3MXqTmEF
foyVCGgBRtronlB9x4Plfb8Psk4GrPkjrWYgO8peKrl0O5+F+sYg7Gj95zCH73BQ
ANzCVNrgD9fs9cyx3ru9CUdEoIxAAJwQFkjm7xr6xqhIlSgnQ7B0uOSTNRcXY6rw
s+PxGneec/kRPRgzjC/QHY6n8QIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBbyMqF
RDsX8zX1EW5qA8AQ8Jb2XqWrVeSO8blMV3WagJ2airMm3+c/82FCwsd/cZ08UXhA
/Kou0gi/F16tV26PiiUdp590Qao3d8H2qxc1rzzULimZPgxH4iA4vRyMHtyZN6h4
7Fdn7O9xNMPu8siOz8rrzsEdEX5URbOMkDLCZsbTIUWVv2XmqrR0K10d5VuLWeLi
r+4G6c6jpa244WmqT9ClqceJ12G1Wnmezy7ybiW0l5M2iuIKFEiRP5Hj0J15o1I2
pXAbKysAdWRHsJSQOtcgO8Vh9k0wo3tKg4HDp1hbrEzoGzOv92Vjg3lG8X+hzbMJ
MQURotHkD4Gk57wL
-----END CERTIFICATE-----

View File

@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA5NHl5TfZtO6zugau2tp5mWIcQYJhuwKTmYeXDLYAGJpoD2Si
xwPL5c8glneIRz1N2EQIZVeaWGbS0FLFlPdOkCkplpW9isYVC4XqKrk5b4HW4+YC
+Cup0k+Kd4NMeZOTUvWr5N6dIpdibkVumBc/pao8VtdwywlCL/PwGRsQtkXrRICz
dtRa3MXqTmEFfoyVCGgBRtronlB9x4Plfb8Psk4GrPkjrWYgO8peKrl0O5+F+sYg
7Gj95zCH73BQANzCVNrgD9fs9cyx3ru9CUdEoIxAAJwQFkjm7xr6xqhIlSgnQ7B0
uOSTNRcXY6rws+PxGneec/kRPRgzjC/QHY6n8QIDAQABAoIBACo3G131tuGtpFTu
xLW11vdYZXQklNlGuWp63IBI162yVv54B5wF9Ek6tH1uIiNaiREcRBxGVEB4/+3V
R4SbN9Ba98RDbgu7TcipdTFaqOEMqFO1bNjSXWtip14zSBmqA2Ur1AHOnFj0awGD
J8tBhsmOpcEz0Ch1VdO5ApPvLV8jH9wQiMI/Q6yYQMtmzTMCUMYdMqe+LOziIOzL
oqN/WXnKL5E5TiO1bIxSpWPbT+IVn1c3/PShmvmRrLWsFUQlkwXJKMYZPO+rCCfe
b+Q9lMLMnj+vOnM3z16WC3aiiJGCZjVTvQ+x22YrBTRPxZmHO2eZ4H/cUQM7Y/tw
I7RjEM0CgYEA9Kxt1t8bWonzBii3P0rwyx0IECvg63k+pp4BpxpeWQKL7NVdSzk3
AyJVcNjUoZgi2kVPdxzZGLrnZfuZ691xQB3oZF0LwBzQ4GFHkTRCB0s8ZA5lcJaI
9pBu91bhz2VOZSTeQWpdMMURjXVyTXZInU1mwzmjVOIAYmO33shH9gcCgYEA72mX
UoIrFPLkOTSZOb7UbjYH01vf6ThQiYCEWg7mD3CbY7n9oobIcQMzNnt7xN4wOl/V
eKfZ7G56q8enfqm45Dyo9aCBCENVzmwO8wLe5UnvJBNL20KjvtwG8w5A6UZQzC7p
3QS+U2zxVQNEeaE6a8Wrq2d1PlhVAHYw8odgNEcCgYBN38+58xrmrz99d1oTuAt5
6kyVsRGOgPGS4HmQMRFUbT4R7DscZSKASd4945WRtTVqmWLYe4MRnvNlfzYXX0zb
ZmmAAClsRP+qWuwHaEWXwrd+9SIOOqtvJrta1/lZJFpWUOy4j10H18Flb7sosnwc
LPWHL4Iv0xriNfDg5Iga4wKBgQDLJBU59SkJBW+Q+oho7vrg6QeK15IOGbJ8eYfT
woCC6VFwNQh5N1QsUELMH8rNKJpTba18SzAl5ThBOY9tciVnw/C5Og9CK6BLHnUw
zWbDtxAq1BSxXsIB2EAtTBLX3MoB9myJFNVJhE7hi3w2mA8yEu+u6IIa/Ghjk+XE
ZAnFUQKBgQDjMinRZrK5wA09jcetI+dNiLnKHoQG6OaXDDsNCatex0O2F36BvVXE
P78qDz/i5aBMWsLx6VDvWJAkBIpZoNS5UsOn17tFaocGUSkcm48bs8Dn6VvsE8Bd
XMPAHyKuILlKYifBvNq5T22KhqKX7yGmk/AeOOiKr2KeMnh27JYrCA==
-----END RSA PRIVATE KEY-----

View File

@@ -0,0 +1,5 @@
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
</IfModule>

View File

@@ -0,0 +1,7 @@
<VirtualHost 127.0.0.1:80>
ServerName status.localhost
<Location /server-status>
Require local
SetHandler server-status
</Location>
</VirtualHost>

View File

@@ -0,0 +1,78 @@
#!/bin/bash
#
# Environment configuration for apache
# The values for all environment variables will be set in the below order of precedence
# 1. Custom environment variables defined below after Bitnami defaults
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
# 3. Environment variables overridden via external files using *_FILE variables (see below)
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
# Load logging library
# shellcheck disable=SC1090,SC1091
. /opt/bitnami/scripts/liblog.sh
export BITNAMI_ROOT_DIR="/opt/bitnami"
export BITNAMI_VOLUME_DIR="/bitnami"
# Logging configuration
export MODULE="${MODULE:-apache}"
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
# variable will be overridden with the value specified in that file
apache_env_vars=(
APACHE_HTTP_PORT_NUMBER
APACHE_HTTPS_PORT_NUMBER
APACHE_SERVER_TOKENS
APACHE_HTTP_PORT
APACHE_HTTPS_PORT
)
for env_var in "${apache_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
if [[ -n "${!file_env_var:-}" ]]; then
if [[ -r "${!file_env_var:-}" ]]; then
export "${env_var}=$(< "${!file_env_var}")"
unset "${file_env_var}"
else
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
fi
fi
done
unset apache_env_vars
export WEB_SERVER_TYPE="apache"
# Paths
export APACHE_BASE_DIR="${BITNAMI_ROOT_DIR}/apache"
export APACHE_BIN_DIR="${APACHE_BASE_DIR}/bin"
export APACHE_CONF_DIR="${APACHE_BASE_DIR}/conf"
export APACHE_HTDOCS_DIR="${APACHE_BASE_DIR}/htdocs"
export APACHE_TMP_DIR="${APACHE_BASE_DIR}/var/run"
export APACHE_LOGS_DIR="${APACHE_BASE_DIR}/logs"
export APACHE_VHOSTS_DIR="${APACHE_CONF_DIR}/vhosts"
export APACHE_HTACCESS_DIR="${APACHE_VHOSTS_DIR}/htaccess"
export APACHE_CONF_FILE="${APACHE_CONF_DIR}/httpd.conf"
export APACHE_PID_FILE="${APACHE_TMP_DIR}/httpd.pid"
export PATH="${APACHE_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}"
# System users (when running with a privileged user)
export APACHE_DAEMON_USER="daemon"
export WEB_SERVER_DAEMON_USER="$APACHE_DAEMON_USER"
export APACHE_DAEMON_GROUP="daemon"
export WEB_SERVER_DAEMON_GROUP="$APACHE_DAEMON_GROUP"
export WEB_SERVER_GROUP="$APACHE_DAEMON_GROUP"
# Apache configuration
export APACHE_DEFAULT_HTTP_PORT_NUMBER="8080"
export WEB_SERVER_DEFAULT_HTTP_PORT_NUMBER="$APACHE_DEFAULT_HTTP_PORT_NUMBER" # only used at build time
export APACHE_DEFAULT_HTTPS_PORT_NUMBER="8443"
export WEB_SERVER_DEFAULT_HTTPS_PORT_NUMBER="$APACHE_DEFAULT_HTTPS_PORT_NUMBER" # only used at build time
APACHE_HTTP_PORT_NUMBER="${APACHE_HTTP_PORT_NUMBER:-"${APACHE_HTTP_PORT:-}"}"
export APACHE_HTTP_PORT_NUMBER="${APACHE_HTTP_PORT_NUMBER:-}"
export WEB_SERVER_HTTP_PORT_NUMBER="$APACHE_HTTP_PORT_NUMBER"
APACHE_HTTPS_PORT_NUMBER="${APACHE_HTTPS_PORT_NUMBER:-"${APACHE_HTTPS_PORT:-}"}"
export APACHE_HTTPS_PORT_NUMBER="${APACHE_HTTPS_PORT_NUMBER:-}"
export WEB_SERVER_HTTPS_PORT_NUMBER="$APACHE_HTTPS_PORT_NUMBER"
export APACHE_SERVER_TOKENS="${APACHE_SERVER_TOKENS:-Prod}"
# Custom environment variables may be defined below

View File

@@ -0,0 +1,37 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libversion.sh
. /opt/bitnami/scripts/libapache.sh
# Load Apache environment
. /opt/bitnami/scripts/apache-env.sh
. /opt/bitnami/scripts/php-env.sh
# Enable required Apache modules
apache_enable_module "mpm_prefork_module"
php_version="$("${PHP_BIN_DIR}/php" -v | grep ^PHP | cut -d' ' -f2))"
php_major_version="$(get_sematic_version "$php_version" 1)"
if [[ "$php_major_version" -eq "8" ]]; then
apache_enable_module "php_module" "modules/libphp.so"
else
apache_enable_module "php${php_major_version}_module" "modules/libphp${php_major_version}.so"
fi
# Disable incompatible Apache modules
apache_disable_module "mpm_event_module"
# Write Apache configuration
apache_php_conf_file="${APACHE_CONF_DIR}/bitnami/php.conf"
cat > "$apache_php_conf_file" <<EOF
AddType application/x-httpd-php .php
DirectoryIndex index.html index.htm index.php
EOF
ensure_apache_configuration_exists "Include \"${apache_php_conf_file}\""

View File

@@ -0,0 +1,7 @@
{{http_listen_configuration}}
{{before_vhost_configuration}}
<VirtualHost {{http_listen_addresses}}>
{{server_name_configuration}}
{{additional_http_configuration}}
{{additional_configuration}}
</VirtualHost>

View File

@@ -0,0 +1,10 @@
{{https_listen_configuration}}
{{before_vhost_configuration}}
<VirtualHost {{https_listen_addresses}}>
{{server_name_configuration}}
SSLEngine on
SSLCertificateFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.crt"
SSLCertificateKeyFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.key"
{{additional_https_configuration}}
{{additional_configuration}}
</VirtualHost>

View File

@@ -0,0 +1,15 @@
{{http_listen_configuration}}
{{before_vhost_configuration}}
<VirtualHost {{http_listen_addresses}}>
{{server_name_configuration}}
DocumentRoot {{document_root}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
{{extra_directory_configuration}}
</Directory>
{{additional_http_configuration}}
{{additional_configuration}}
{{htaccess_include}}
</VirtualHost>

View File

@@ -0,0 +1,18 @@
{{https_listen_configuration}}
{{before_vhost_configuration}}
<VirtualHost {{https_listen_addresses}}>
{{server_name_configuration}}
SSLEngine on
SSLCertificateFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.crt"
SSLCertificateKeyFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.key"
DocumentRoot {{document_root}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
{{extra_directory_configuration}}
</Directory>
{{additional_https_configuration}}
{{additional_configuration}}
{{htaccess_include}}
</VirtualHost>

View File

@@ -0,0 +1,9 @@
{{prefix_conf}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
{{extra_directory_configuration}}
</Directory>
{{additional_configuration}}
{{htaccess_include}}

View File

@@ -0,0 +1,11 @@
{{http_listen_configuration}}
{{before_vhost_configuration}}
<VirtualHost {{http_listen_addresses}}>
{{server_name_configuration}}
{{proxy_configuration}}
{{proxy_http_configuration}}
ProxyPass / {{proxy_address}}
ProxyPassReverse / {{proxy_address}}
{{additional_http_configuration}}
{{additional_configuration}}
</VirtualHost>

View File

@@ -0,0 +1,14 @@
{{https_listen_configuration}}
{{before_vhost_configuration}}
<VirtualHost {{https_listen_addresses}}>
{{server_name_configuration}}
SSLEngine on
SSLCertificateFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.crt"
SSLCertificateKeyFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.key"
{{proxy_configuration}}
{{proxy_https_configuration}}
ProxyPass / {{proxy_address}}
ProxyPassReverse / {{proxy_address}}
{{additional_https_configuration}}
{{additional_configuration}}
</VirtualHost>

View File

@@ -0,0 +1,11 @@
{{prefix_conf}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
{{proxy_configuration}}
ProxyPass / {{proxy_address}}
ProxyPassReverse / {{proxy_address}}
{{extra_directory_configuration}}
</Directory>
{{additional_configuration}}

View File

@@ -0,0 +1,16 @@
{{http_listen_configuration}}
{{before_vhost_configuration}}
PassengerPreStart http://localhost:{{http_port}}/
<VirtualHost {{http_listen_addresses}}>
{{server_name_configuration}}
DocumentRoot {{document_root}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
PassengerEnabled on
{{extra_directory_configuration}}
</Directory>
{{additional_http_configuration}}
{{additional_configuration}}
</VirtualHost>

View File

@@ -0,0 +1,19 @@
{{https_listen_configuration}}
{{before_vhost_configuration}}
PassengerPreStart https://localhost:{{https_port}}/
<VirtualHost {{https_listen_addresses}}>
{{server_name_configuration}}
SSLEngine on
SSLCertificateFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.crt"
SSLCertificateKeyFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.key"
DocumentRoot {{document_root}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
PassengerEnabled on
{{extra_directory_configuration}}
</Directory>
{{additional_https_configuration}}
{{additional_configuration}}
</VirtualHost>

View File

@@ -0,0 +1,9 @@
{{prefix_conf}}
<Directory "{{document_root}}">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride {{allow_override}}
{{acl_configuration}}
PassengerEnabled on
{{extra_directory_configuration}}
</Directory>
{{additional_configuration}}

View File

@@ -0,0 +1,29 @@
# Default SSL Virtual Host configuration.
<IfModule !ssl_module>
LoadModule ssl_module modules/mod_ssl.so
</IfModule>
Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
SSLPassPhraseDialog builtin
SSLSessionCache "shmcb:{{APACHE_LOGS_DIR}}/ssl_scache(512000)"
SSLSessionCacheTimeout 300
<VirtualHost _default_:443>
DocumentRoot "{{APACHE_BASE_DIR}}/htdocs"
SSLEngine on
SSLCertificateFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.crt"
SSLCertificateKeyFile "{{APACHE_CONF_DIR}}/bitnami/certs/server.key"
<Directory "{{APACHE_BASE_DIR}}/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Error Documents
ErrorDocument 503 /503.html
</VirtualHost>

View File

@@ -0,0 +1,18 @@
# Default Virtual Host configuration.
# Let Apache know we're behind a SSL reverse proxy
SetEnvIf X-Forwarded-Proto https HTTPS=on
<VirtualHost _default_:80>
DocumentRoot "{{APACHE_BASE_DIR}}/htdocs"
<Directory "{{APACHE_BASE_DIR}}/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Error Documents
ErrorDocument 503 /503.html
</VirtualHost>
Include "{{APACHE_CONF_DIR}}/bitnami/bitnami-ssl.conf"

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
#set -o xtrace
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/libbitnami.sh
. /opt/bitnami/scripts/liblog.sh
# Load Apache environment
. /opt/bitnami/scripts/apache-env.sh
print_welcome_page
if [[ "$*" == *"/opt/bitnami/scripts/apache/run.sh"* ]]; then
info "** Starting Apache setup **"
/opt/bitnami/scripts/apache/setup.sh
info "** Apache setup finished! **"
fi
echo ""
exec "$@"

View File

@@ -0,0 +1,116 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/liblog.sh
########################
# Sets up the default Bitnami configuration
# Globals:
# APACHE_*
# Arguments:
# None
# Returns:
# None
#########################
apache_setup_bitnami_config() {
local template_dir="${BITNAMI_ROOT_DIR}/scripts/apache/bitnami-templates"
# Enable Apache modules
local -a modules_to_enable=(
"deflate_module"
"negotiation_module"
"proxy[^\s]*_module"
"rewrite_module"
"slotmem_shm_module"
"socache_shmcb_module"
"ssl_module"
"status_module"
"version_module"
)
for module in "${modules_to_enable[@]}"; do
apache_enable_module "$module"
done
# Disable Apache modules
local -a modules_to_disable=(
"http2_module"
"proxy_hcheck_module"
)
for module in "${modules_to_disable[@]}"; do
apache_disable_module "$module"
done
# Bitnami customizations
render-template "${template_dir}/bitnami.conf.tpl" > "${APACHE_CONF_DIR}/bitnami/bitnami.conf"
render-template "${template_dir}/bitnami-ssl.conf.tpl" > "${APACHE_CONF_DIR}/bitnami/bitnami-ssl.conf"
# Add new configuration only once, to avoid a second postunpack run breaking Apache
local apache_conf_add
apache_conf_add="$(cat <<EOF
Include "${APACHE_CONF_DIR}/extra/httpd-default.conf"
PidFile "${APACHE_PID_FILE}"
TraceEnable Off
ServerTokens ${APACHE_SERVER_TOKENS}
Include "${APACHE_CONF_DIR}/deflate.conf"
IncludeOptional "${APACHE_VHOSTS_DIR}/*.conf"
Include "${APACHE_CONF_DIR}/bitnami/bitnami.conf"
EOF
)"
ensure_apache_configuration_exists "$apache_conf_add" "${APACHE_CONF_DIR}/bitnami/bitnami.conf"
# Configure the default ports since the container is non root by default
apache_configure_http_port "$APACHE_DEFAULT_HTTP_PORT_NUMBER"
apache_configure_https_port "$APACHE_DEFAULT_HTTPS_PORT_NUMBER"
# Patch the HTTPoxy vulnerability - see: https://docs.bitnami.com/general/security/security-2016-07-18/
apache_patch_httpoxy_vulnerability
# Remove unnecessary directories that come with the tarball
rm -rf "${BITNAMI_ROOT_DIR}/certs" "${BITNAMI_ROOT_DIR}/conf"
}
########################
# Patches the HTTPoxy vulnerability - see: https://docs.bitnami.com/general/security/security-2016-07-18/
# Globals:
# APACHE_CONF_FILE
# Arguments:
# None
# Returns:
# None
#########################
apache_patch_httpoxy_vulnerability() {
# Apache HTTPD includes the HTTPoxy fix since 2016, so we only add it if not present
if ! grep -q "RequestHeader unset Proxy" "$APACHE_CONF_FILE"; then
cat >>"$APACHE_CONF_FILE" <<EOF
<IfModule mod_headers.c>
RequestHeader unset Proxy
</IfModule>
EOF
fi
}
# Load Apache environment
. /opt/bitnami/scripts/apache-env.sh
apache_setup_bitnami_config
# Ensure non-root user has write permissions on a set of directories
for dir in "$APACHE_TMP_DIR" "$APACHE_CONF_DIR" "$APACHE_LOGS_DIR" "$APACHE_VHOSTS_DIR" "$APACHE_HTACCESS_DIR" "$APACHE_HTDOCS_DIR"; do
ensure_dir_exists "$dir"
chmod -R g+rwX "$dir"
done
# Create 'apache2' symlink pointing to the 'apache' directory, for compatibility with Bitnami Docs guides
ln -sf apache "${BITNAMI_ROOT_DIR}/apache2"
ln -sf "/dev/stdout" "${APACHE_LOGS_DIR}/access_log"
ln -sf "/dev/stderr" "${APACHE_LOGS_DIR}/error_log"

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/liblog.sh
# Load Apache environment
. /opt/bitnami/scripts/apache-env.sh
info "** Reloading Apache configuration **"
exec "${APACHE_BIN_DIR}/apachectl" -k graceful

View File

@@ -0,0 +1,17 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
# Load Apache environment variables
. /opt/bitnami/scripts/apache-env.sh
/opt/bitnami/scripts/apache/stop.sh
/opt/bitnami/scripts/apache/start.sh

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/liblog.sh
# Load Apache environment
. /opt/bitnami/scripts/apache-env.sh
info "** Starting Apache **"
exec "${APACHE_BIN_DIR}/httpd" -f "$APACHE_CONF_FILE" -D "FOREGROUND"

View File

@@ -0,0 +1,63 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
# Load Apache environment
. /opt/bitnami/scripts/apache-env.sh
# Ensure Apache environment variables are valid
apache_validate
# Ensure Apache daemon user exists when running as 'root'
am_i_root && ensure_user_exists "$APACHE_DAEMON_USER" --group "$APACHE_DAEMON_GROUP"
# Copy vhosts files
if ! is_dir_empty "/vhosts"; then
info "Found mounted virtual hosts in '/vhosts'. Copying them to '${APACHE_BASE_DIR}/conf/vhosts'"
cp -Lr "/vhosts/." "${APACHE_VHOSTS_DIR}"
fi
# Mount certificate files
if ! is_dir_empty "${APACHE_BASE_DIR}/certs"; then
warn "The directory '${APACHE_BASE_DIR}/certs' was externally mounted. This is a legacy configuration and will be deprecated soon. Please mount certificate files at '/certs' instead. Find an example at: https://github.com/bitnami/containers/tree/main/bitnami/apache#using-custom-ssl-certificates"
warn "Restoring certificates at '${APACHE_BASE_DIR}/certs' to '${APACHE_CONF_DIR}/bitnami/certs'"
rm -rf "${APACHE_CONF_DIR}/bitnami/certs"
ln -sf "${APACHE_BASE_DIR}/certs" "${APACHE_CONF_DIR}/bitnami/certs"
elif ! is_dir_empty "/certs"; then
info "Mounting certificates files from '/certs'"
rm -rf "${APACHE_CONF_DIR}/bitnami/certs"
ln -sf "/certs" "${APACHE_CONF_DIR}/bitnami/certs"
fi
# Mount application files
if ! is_dir_empty "/app"; then
info "Mounting application files from '/app'"
rm -rf "$APACHE_HTDOCS_DIR"
ln -sf "/app" "$APACHE_HTDOCS_DIR"
fi
# Restore persisted configuration files (deprecated)
if ! is_dir_empty "/bitnami/apache/conf"; then
warn "The directory '/bitnami/apache/conf' was externally mounted. This is a legacy configuration and will be deprecated soon. Please mount certificate files at '${APACHE_CONF_DIR}' instead. Find an example at: https://github.com/bitnami/containers/tree/main/bitnami/apache#full-configuration"
warn "Restoring configuration at '/bitnami/apache/conf' to '${APACHE_CONF_DIR}'"
rm -rf "$APACHE_CONF_DIR"
ln -sf "/bitnami/apache/conf" "$APACHE_CONF_DIR"
fi
# Update ports in configuration
[[ -n "$APACHE_HTTP_PORT_NUMBER" ]] && info "Configuring the HTTP port" && apache_configure_http_port "$APACHE_HTTP_PORT_NUMBER"
[[ -n "$APACHE_HTTPS_PORT_NUMBER" ]] && info "Configuring the HTTPS port" && apache_configure_https_port "$APACHE_HTTPS_PORT_NUMBER"
# Configure ServerTokens with user values
[[ -n "$APACHE_SERVER_TOKENS" ]] && info "Configuring Apache ServerTokens directive" && apache_configure_server_tokens "$APACHE_SERVER_TOKENS"
# Fix logging issue when running as root
! am_i_root || chmod o+w "$(readlink /dev/stdout)" "$(readlink /dev/stderr)"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/liblog.sh
# Load Apache environment variables
. /opt/bitnami/scripts/apache-env.sh
error_code=0
if is_apache_not_running; then
"${APACHE_BIN_DIR}/httpd" -f "$APACHE_CONF_FILE"
if ! retry_while "is_apache_running"; then
error "apache did not start"
error_code=1
else
info "apache started"
fi
else
info "apache is already running"
fi
exit "$error_code"

View File

@@ -0,0 +1,21 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/liblog.sh
# Load Apache environment variables
. /opt/bitnami/scripts/apache-env.sh
if is_apache_running; then
info "apache is already running"
else
info "apache is not running"
fi

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libapache.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/liblog.sh
# Load Apache environment variables
. /opt/bitnami/scripts/apache-env.sh
error_code=0
if is_apache_running; then
BITNAMI_QUIET=1 apache_stop
if ! retry_while "is_apache_not_running"; then
error "apache could not be stopped"
error_code=1
else
info "apache stopped"
fi
else
info "apache is not running"
fi
exit "$error_code"

View File

@@ -0,0 +1,118 @@
#!/bin/bash
#
# Environment configuration for drupal
# The values for all environment variables will be set in the below order of precedence
# 1. Custom environment variables defined below after Bitnami defaults
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
# 3. Environment variables overridden via external files using *_FILE variables (see below)
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
# Load logging library
# shellcheck disable=SC1090,SC1091
. /opt/bitnami/scripts/liblog.sh
export BITNAMI_ROOT_DIR="/opt/bitnami"
export BITNAMI_VOLUME_DIR="/bitnami"
# Logging configuration
export MODULE="${MODULE:-drupal}"
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
# variable will be overridden with the value specified in that file
drupal_env_vars=(
DRUPAL_DATA_TO_PERSIST
DRUPAL_PROFILE
DRUPAL_SITE_NAME
DRUPAL_SKIP_BOOTSTRAP
DRUPAL_ENABLE_MODULES
DRUPAL_CONFIG_SYNC_DIR
DRUPAL_HASH_SALT
DRUPAL_USERNAME
DRUPAL_PASSWORD
DRUPAL_EMAIL
DRUPAL_SMTP_HOST
DRUPAL_SMTP_PORT_NUMBER
DRUPAL_SMTP_USER
DRUPAL_SMTP_PASSWORD
DRUPAL_SMTP_PROTOCOL
DRUPAL_DATABASE_HOST
DRUPAL_DATABASE_PORT_NUMBER
DRUPAL_DATABASE_NAME
DRUPAL_DATABASE_USER
DRUPAL_DATABASE_PASSWORD
DRUPAL_DATABASE_TLS_CA_FILE
SMTP_HOST
SMTP_PORT
DRUPAL_SMTP_PORT
SMTP_USER
SMTP_PASSWORD
SMTP_PROTOCOL
MARIADB_HOST
MARIADB_PORT_NUMBER
)
for env_var in "${drupal_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
if [[ -n "${!file_env_var:-}" ]]; then
if [[ -r "${!file_env_var:-}" ]]; then
export "${env_var}=$(< "${!file_env_var}")"
unset "${file_env_var}"
else
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
fi
fi
done
unset drupal_env_vars
# Paths
export DRUPAL_BASE_DIR="${BITNAMI_ROOT_DIR}/drupal"
export DRUPAL_CONF_FILE="${DRUPAL_BASE_DIR}/sites/default/settings.php"
export DRUPAL_MODULES_DIR="${DRUPAL_BASE_DIR}/modules"
# Drupal persistence configuration
export DRUPAL_VOLUME_DIR="${BITNAMI_VOLUME_DIR}/drupal"
export DRUPAL_MOUNTED_CONF_FILE="${DRUPAL_VOLUME_DIR}/settings.php"
export DRUPAL_DATA_TO_PERSIST="${DRUPAL_DATA_TO_PERSIST:-sites/ themes/ modules/ profiles/}"
# Drupal configuration
export DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}" # only used during the first initialization
export DRUPAL_SITE_NAME="${DRUPAL_SITE_NAME:-My blog}" # only used during the first initialization
export DRUPAL_SKIP_BOOTSTRAP="${DRUPAL_SKIP_BOOTSTRAP:-}" # only used during the first initialization
export DRUPAL_ENABLE_MODULES="${DRUPAL_ENABLE_MODULES:-}" # only used during the first initialization
export DRUPAL_CONFIG_SYNC_DIR="${DRUPAL_CONFIG_SYNC_DIR:-}" # only used during the first initialization
export DRUPAL_HASH_SALT="${DRUPAL_HASH_SALT:-}" # only used during the first initialization
# Drupal credentials
export DRUPAL_USERNAME="${DRUPAL_USERNAME:-user}" # only used during the first initialization
export DRUPAL_PASSWORD="${DRUPAL_PASSWORD:-bitnami}" # only used during the first initialization
export DRUPAL_EMAIL="${DRUPAL_EMAIL:-user@example.com}" # only used during the first initialization
# Drupal SMTP credentials
DRUPAL_SMTP_HOST="${DRUPAL_SMTP_HOST:-"${SMTP_HOST:-}"}"
export DRUPAL_SMTP_HOST="${DRUPAL_SMTP_HOST:-}" # only used during the first initialization
DRUPAL_SMTP_PORT_NUMBER="${DRUPAL_SMTP_PORT_NUMBER:-"${SMTP_PORT:-}"}"
DRUPAL_SMTP_PORT_NUMBER="${DRUPAL_SMTP_PORT_NUMBER:-"${DRUPAL_SMTP_PORT:-}"}"
export DRUPAL_SMTP_PORT_NUMBER="${DRUPAL_SMTP_PORT_NUMBER:-25}" # only used during the first initialization
DRUPAL_SMTP_USER="${DRUPAL_SMTP_USER:-"${SMTP_USER:-}"}"
export DRUPAL_SMTP_USER="${DRUPAL_SMTP_USER:-}" # only used during the first initialization
DRUPAL_SMTP_PASSWORD="${DRUPAL_SMTP_PASSWORD:-"${SMTP_PASSWORD:-}"}"
export DRUPAL_SMTP_PASSWORD="${DRUPAL_SMTP_PASSWORD:-}" # only used during the first initialization
DRUPAL_SMTP_PROTOCOL="${DRUPAL_SMTP_PROTOCOL:-"${SMTP_PROTOCOL:-}"}"
export DRUPAL_SMTP_PROTOCOL="${DRUPAL_SMTP_PROTOCOL:-standard}" # only used during the first initialization
# Database configuration
export DRUPAL_DEFAULT_DATABASE_HOST="mariadb" # only used at build time
DRUPAL_DATABASE_HOST="${DRUPAL_DATABASE_HOST:-"${MARIADB_HOST:-}"}"
export DRUPAL_DATABASE_HOST="${DRUPAL_DATABASE_HOST:-$DRUPAL_DEFAULT_DATABASE_HOST}" # only used during the first initialization
DRUPAL_DATABASE_PORT_NUMBER="${DRUPAL_DATABASE_PORT_NUMBER:-"${MARIADB_PORT_NUMBER:-}"}"
export DRUPAL_DATABASE_PORT_NUMBER="${DRUPAL_DATABASE_PORT_NUMBER:-3306}" # only used during the first initialization
export DRUPAL_DATABASE_NAME="${DRUPAL_DATABASE_NAME:-bitnami_drupal}" # only used during the first initialization
export DRUPAL_DATABASE_USER="${DRUPAL_DATABASE_USER:-bn_drupal}" # only used during the first initialization
export DRUPAL_DATABASE_PASSWORD="${DRUPAL_DATABASE_PASSWORD:-}" # only used during the first initialization
export DRUPAL_DATABASE_TLS_CA_FILE="${DRUPAL_DATABASE_TLS_CA_FILE:-}" # only used during the first initialization
# PHP configuration
export PHP_DEFAULT_MEMORY_LIMIT="256M" # only used at build time
# Custom environment variables may be defined below

View File

@@ -0,0 +1,31 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load Drupal environment
. /opt/bitnami/scripts/drupal-env.sh
# Load libraries
. /opt/bitnami/scripts/libbitnami.sh
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libwebserver.sh
print_welcome_page
if [[ "$1" = "/opt/bitnami/scripts/$(web_server_type)/run.sh" || "$1" = "/opt/bitnami/scripts/nginx-php-fpm/run.sh" ]]; then
info "** Starting Drupal setup **"
/opt/bitnami/scripts/"$(web_server_type)"/setup.sh
/opt/bitnami/scripts/php/setup.sh
/opt/bitnami/scripts/mysql-client/setup.sh
/opt/bitnami/scripts/drupal/setup.sh
/post-init.sh
info "** Drupal setup finished! **"
fi
echo ""
exec "$@"

View File

@@ -0,0 +1,127 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load Drupal environment
. /opt/bitnami/scripts/drupal-env.sh
# Load PHP environment for 'php_conf_set' (after 'drupal-env.sh' so that MODULE is not set to a wrong value)
. /opt/bitnami/scripts/php-env.sh
# Load libraries
. /opt/bitnami/scripts/libdrupal.sh
. /opt/bitnami/scripts/libfile.sh
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/libwebserver.sh
# Load web server environment and functions (after Drupal environment file so MODULE is not set to a wrong value)
. "/opt/bitnami/scripts/$(web_server_type)-env.sh"
# Enable Drupal configuration file
[[ ! -f "$DRUPAL_CONF_FILE" ]] && cp "${DRUPAL_BASE_DIR}/sites/default/default.settings.php" "$DRUPAL_CONF_FILE"
# Create .htaccess file to avoid warning in Drupal administration panel
drupal_fix_htaccess_warning_protection
# Ensure the Drupal base directory exists and has proper permissions
info "Configuring file permissions for Drupal"
for dir in "$DRUPAL_BASE_DIR" "${DRUPAL_BASE_DIR}/sites/default/files" "$DRUPAL_VOLUME_DIR" "${HOME}/.drush"; do
ensure_dir_exists "$dir"
configure_permissions_ownership "$dir" -d "775" -f "664"
done
for dir in "${DRUPAL_BASE_DIR}/themes" "${DRUPAL_BASE_DIR}/modules" "${DRUPAL_BASE_DIR}/sites/default/files"; do
ensure_dir_exists "$dir"
configure_permissions_ownership "$dir" -u "$WEB_SERVER_DAEMON_USER" -g "root"
done
chown "$WEB_SERVER_DAEMON_USER" "${DRUPAL_BASE_DIR}/sites/default"
chown "$WEB_SERVER_DAEMON_USER" "$DRUPAL_CONF_FILE"
for script in "${DRUPAL_BASE_DIR}/vendor/bin/drush" "${DRUPAL_BASE_DIR}/vendor/drush/drush/drush" "${DRUPAL_BASE_DIR}/vendor/drush/drush/drush.launcher" "${DRUPAL_BASE_DIR}/vendor/bin/drush.launcher"; do
[[ -f "$script" ]] && chmod +x "$script"
done
# Configure Drupal based on build-time defaults
drupal_conf_set "\$settings['trusted_host_patterns']" "array('^.*$')" yes
# Configure required PHP options for application to work properly, based on build-time defaults
info "Configuring default PHP options for Drupal"
php_conf_set memory_limit "$PHP_DEFAULT_MEMORY_LIMIT"
# Enable default web server configuration for Drupal
info "Creating default web server configuration for Drupal"
web_server_validate
ensure_web_server_app_configuration_exists "drupal" \
--type php \
--nginx-additional-configuration $'
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/sites/.*/private/ {
return 403;
}
# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}
location / {
try_files $uri /index.php?$query_string;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
# Don\'t allow direct access to PHP files in the vendor directory.
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
# Fighting with Styles? This little gem is amazing.
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
# Handle private files through Drupal. Private file\'s path can come
# with a language prefix.
location ~ ^(/[a-z\-]+)?/system/files/ {
try_files $uri /index.php?$query_string;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}'
# Fix common issues running Drupal on top of the NGINX web server, if enabled
# See: https://pantheon.io/blog/update-your-nginx-config-drupal-8
nginx_php_fpm_conf_file="${BITNAMI_ROOT_DIR}/nginx/conf/bitnami/php-fpm.conf"
if [[ -f "$nginx_php_fpm_conf_file" ]]; then
replace_in_file "$nginx_php_fpm_conf_file" '^(\s*)(fastcgi_index\s+index\.php;)$' '\1\2\n\1fastcgi_split_path_info ^(.+?\.php)(|/.*)$;'
replace_in_file "$nginx_php_fpm_conf_file" '(\s\\.php\$)(\s)' '\1|^/update.php\2'
fi
# Re-create .htaccess file after being moved into 'apache/conf/vhosts/htaccess' directory, to avoid Drupal warning
drupal_fix_htaccess_warning_protection

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load Drupal environment
. /opt/bitnami/scripts/drupal-env.sh
# Load MySQL Client environment for 'mysql_remote_execute' (after 'drupal-env.sh' so that MODULE is not set to a wrong value)
if [[ -f /opt/bitnami/scripts/mysql-client-env.sh ]]; then
. /opt/bitnami/scripts/mysql-client-env.sh
elif [[ -f /opt/bitnami/scripts/mysql-env.sh ]]; then
. /opt/bitnami/scripts/mysql-env.sh
elif [[ -f /opt/bitnami/scripts/mariadb-env.sh ]]; then
. /opt/bitnami/scripts/mariadb-env.sh
fi
# Load libraries
. /opt/bitnami/scripts/libdrupal.sh
. /opt/bitnami/scripts/libwebserver.sh
# Load web server environment and functions (after Drupal environment file so MODULE is not set to a wrong value)
. "/opt/bitnami/scripts/$(web_server_type)-env.sh"
# Ensure Drupal environment variables are valid
drupal_validate
# Update web server configuration with runtime environment (needs to happen before the initialization)
web_server_update_app_configuration "drupal"
# Ensure Drupal is initialized
drupal_initialize

View File

@@ -0,0 +1,804 @@
#!/bin/bash
#
# Bitnami Apache library
# shellcheck disable=SC1091
# Load Generic Libraries
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/libfile.sh
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/libvalidations.sh
. /opt/bitnami/scripts/libservice.sh
########################
# Validate settings in APACHE_* env vars
# Globals:
# APACHE_*
# Arguments:
# None
# Returns:
# None
#########################
apache_validate() {
debug "Validating settings in APACHE_* environment variables"
local error_code=0
# Auxiliary functions
print_validation_error() {
error "$1"
error_code=1
}
check_allowed_port() {
local port_var="${1:?missing port variable}"
local -a validate_port_args=()
! am_i_root && validate_port_args+=("-unprivileged")
validate_port_args+=("${!port_var}")
if ! err=$(validate_port "${validate_port_args[@]}"); then
print_validation_error "An invalid port was specified in the environment variable ${port_var}: ${err}."
fi
}
[[ -w "$APACHE_CONF_FILE" ]] || warn "The Apache configuration file '${APACHE_CONF_FILE}' is not writable. Configurations based on environment variables will not be applied."
if [[ -n "$APACHE_HTTP_PORT_NUMBER" ]] && [[ -n "$APACHE_HTTPS_PORT_NUMBER" ]]; then
if [[ "$APACHE_HTTP_PORT_NUMBER" -eq "$APACHE_HTTPS_PORT_NUMBER" ]]; then
print_validation_error "APACHE_HTTP_PORT_NUMBER and APACHE_HTTPS_PORT_NUMBER are bound to the same port!"
fi
fi
[[ -n "$APACHE_HTTP_PORT_NUMBER" ]] && check_allowed_port APACHE_HTTP_PORT_NUMBER
[[ -n "$APACHE_HTTPS_PORT_NUMBER" ]] && check_allowed_port APACHE_HTTPS_PORT_NUMBER
[[ "$error_code" -eq 0 ]] || exit "$error_code"
}
########################
# Configure Apache's HTTP port
# Globals:
# APACHE_CONF_FILE, APACHE_CONF_DIR
# Arguments:
# None
# Returns:
# None
#########################
apache_configure_http_port() {
local -r port=${1:?missing port}
local -r listen_exp="s|^\s*Listen\s+([^:]*:)?[0-9]+\s*$|Listen ${port}|"
local -r server_name_exp="s|^\s*#?\s*ServerName\s+([^:\s]+)(:[0-9]+)?$|ServerName \1:${port}|"
local -r vhost_exp="s|VirtualHost\s+([^:>]+)(:[0-9]+)|VirtualHost \1:${port}|"
local apache_configuration
if [[ -w "$APACHE_CONF_FILE" ]]; then
debug "Configuring port ${port} on file ${APACHE_CONF_FILE}"
apache_configuration="$(sed -E -e "$listen_exp" -e "$server_name_exp" "$APACHE_CONF_FILE")"
echo "$apache_configuration" > "$APACHE_CONF_FILE"
fi
if [[ -w "${APACHE_CONF_DIR}/bitnami/bitnami.conf" ]]; then
debug "Configuring port ${port} on file ${APACHE_CONF_DIR}/bitnami/bitnami.conf"
apache_configuration="$(sed -E "$vhost_exp" "${APACHE_CONF_DIR}/bitnami/bitnami.conf")"
echo "$apache_configuration" > "${APACHE_CONF_DIR}/bitnami/bitnami.conf"
fi
if [[ -w "${APACHE_VHOSTS_DIR}/00_status-vhost.conf" ]]; then
debug "Configuring port ${port} on file ${APACHE_VHOSTS_DIR}/00_status-vhost.conf"
apache_configuration="$(sed -E "$vhost_exp" "${APACHE_VHOSTS_DIR}/00_status-vhost.conf")"
echo "$apache_configuration" > "${APACHE_VHOSTS_DIR}/00_status-vhost.conf"
fi
}
########################
# Configure Apache's HTTPS port
# Globals:
# APACHE_CONF_DIR
# Arguments:
# None
# Returns:
# None
#########################
apache_configure_https_port() {
local -r port=${1:?missing port}
local -r listen_exp="s|^\s*Listen\s+([^:]*:)?[0-9]+\s*$|Listen ${port}|"
local -r vhost_exp="s|VirtualHost\s+([^:>]+)(:[0-9]+)|VirtualHost \1:${port}|"
local apache_configuration
if [[ -w "${APACHE_CONF_DIR}/bitnami/bitnami-ssl.conf" ]]; then
debug "Configuring port ${port} on file ${APACHE_CONF_DIR}/bitnami/bitnami-ssl.conf"
apache_configuration="$(sed -E -e "$listen_exp" -e "$vhost_exp" "${APACHE_CONF_DIR}/bitnami/bitnami-ssl.conf")"
echo "$apache_configuration" > "${APACHE_CONF_DIR}/bitnami/bitnami-ssl.conf"
fi
}
########################
# Configure Apache's ServerTokens directive
# Globals:
# APACHE_CONF_DIR
# Arguments:
# $1 - Value for ServerTokens directive
# Returns:
# None
#########################
apache_configure_server_tokens() {
local -r value=${1:?missing value}
local -r server_tokens_exp="s|^\s*ServerTokens\s+\w+\s*$|ServerTokens ${value}|"
local apache_configuration
if [[ -w "$APACHE_CONF_FILE" ]]; then
debug "Configuring ServerTokens ${value} on file ${APACHE_CONF_FILE}"
apache_configuration="$(sed -E -e "$server_tokens_exp" "$APACHE_CONF_FILE")"
echo "$apache_configuration" > "$APACHE_CONF_FILE"
fi
}
########################
# Enable a module in the Apache configuration file
# Globals:
# APACHE_CONF_FILE
# Arguments:
# $1 - Module to enable
# $2 - Path to module .so file (optional if already defined in httpd.conf)
# Returns:
# None
#########################
apache_enable_module() {
local -r name="${1:?missing name}"
local -r file="${2:-}"
local -r regex="[#\s]*(LoadModule\s+${name}\s+.*)$"
local apache_configuration
if [[ -w "$APACHE_CONF_FILE" ]]; then
debug "Enabling module '${name}'"
if grep -q -E "$regex" "$APACHE_CONF_FILE"; then
# Uncomment line if the module was already defined
replace_in_file "$APACHE_CONF_FILE" "$regex" "\1"
elif [[ -n "$file" ]]; then
# Add right after the last LoadModule, so all Apache modules are organized in the same section of the file
append_file_after_last_match "$APACHE_CONF_FILE" "^[#\s]*LoadModule" "LoadModule ${name} ${file}"
else
error "Module ${name} was not defined in ${APACHE_CONF_FILE}. Please specify the 'file' parameter for 'apache_enable_module'."
fi
fi
}
########################
# Disable a module in the Apache configuration file
# Globals:
# APACHE_CONF_FILE
# Arguments:
# $1 - Module to disable
# Returns:
# None
#########################
apache_disable_module() {
local -r name="${1:?missing name}"
local -r file="${2:-}"
local -r regex="[#\s]*(LoadModule\s+${name}\s+.*)$"
local apache_configuration
if [[ -w "$APACHE_CONF_FILE" ]]; then
debug "Disabling module '${name}'"
replace_in_file "$APACHE_CONF_FILE" "$regex" "#\1"
fi
}
########################
# Stop Apache
# Globals:
# APACHE_*
# Arguments:
# None
# Returns:
# None
#########################
apache_stop() {
is_apache_not_running && return
stop_service_using_pid "$APACHE_PID_FILE"
}
########################
# Check if Apache is running
# Globals:
# APACHE_PID_FILE
# Arguments:
# None
# Returns:
# Whether Apache is running
########################
is_apache_running() {
local pid
pid="$(get_pid_from_file "$APACHE_PID_FILE")"
if [[ -n "$pid" ]]; then
is_service_running "$pid"
else
false
fi
}
########################
# Check if Apache is running
# Globals:
# APACHE_PID_FILE
# Arguments:
# None
# Returns:
# Whether Apache is not running
########################
is_apache_not_running() {
! is_apache_running
}
########################
# Ensure configuration gets added to the main Apache configuration file
# Globals:
# APACHE_*
# Arguments:
# $1 - configuration string
# $2 - pattern to use for checking if the configuration already exists (default: $1)
# Returns:
# None
########################
ensure_apache_configuration_exists() {
local -r conf="${1:?conf missing}"
local -r pattern="${2:-"$conf"}"
# Enable configuration by appending to httpd.conf
if ! grep -E -q "$pattern" "$APACHE_CONF_FILE"; then
if is_file_writable "$APACHE_CONF_FILE"; then
cat >> "$APACHE_CONF_FILE" <<< "$conf"
else
error "Could not add the following configuration to '${APACHE_CONF_FILE}:"
error ""
error "$(indent "$conf" 4)"
error ""
error "Include the configuration manually and try again."
return 1
fi
fi
}
########################
# Collect all the .htaccess files from /opt/bitnami/$name and write the result in the 'htaccess' directory
# Globals:
# APACHE_*
# Arguments:
# $1 - App name
# $2 - Overwrite the original .htaccess with the explanation text (defaults to 'yes')
# Flags:
# --document-root - Path to document root directory
# Returns:
# None
########################
apache_replace_htaccess_files() {
local -r app="${1:?missing app}"
local -r result_file="${APACHE_HTACCESS_DIR}/${app}-htaccess.conf"
# Default options
local document_root="${BITNAMI_ROOT_DIR}/${app}"
local overwrite="yes"
local -a htaccess_files
local htaccess_dir
local htaccess_contents
# Validate arguments
shift
while [[ "$#" -gt 0 ]]; do
case "$1" in
--document-root)
shift
document_root="$1"
;;
--overwrite)
shift
overwrite="$1"
;;
*)
echo "Invalid command line flag ${1}" >&2
return 1
;;
esac
shift
done
if is_file_writable "$result_file"; then
# Locate all .htaccess files inside the document root
read -r -a htaccess_files <<< "$(find "$document_root" -name .htaccess -print0 | xargs -0)"
[[ "${#htaccess_files[@]}" = 0 ]] && return
# Create file with root group write privileges, so it can be modified in non-root containers
[[ ! -f "$result_file" ]] && touch "$result_file" && chmod g+rw "$result_file"
for htaccess_file in "${htaccess_files[@]}"; do
htaccess_dir="$(dirname "$htaccess_file")"
htaccess_contents="$(indent "$(< "$htaccess_file")" 2)"
# Skip if it was already included to the resulting htaccess file
if grep -q "^<Directory \"$htaccess_dir\">" <<< "$htaccess_contents"; then
continue
fi
# Add to the htaccess file
cat >> "$result_file" <<EOF
<Directory "${htaccess_dir}">
${htaccess_contents}
</Directory>
EOF
# Overwrite the original .htaccess with the explanation text
if is_boolean_yes "$overwrite"; then
echo "# This configuration has been moved to the ${result_file} config file for performance and security reasons" > "$htaccess_file"
fi
done
elif [[ ! -f "$result_file" ]]; then
error "Could not create htaccess for ${app} at '${result_file}'. Check permissions and ownership for parent directories."
return 1
else
warn "The ${app} htaccess file '${result_file}' is not writable. Configurations based on environment variables will not be applied for this file."
return
fi
}
########################
# Ensure an Apache application configuration exists (in virtual host format)
# Globals:
# APACHE_*
# Arguments:
# $1 - App name
# Flags:
# --type - Application type, which has an effect on what configuration template will be used, allowed values: php, (empty)
# --hosts - Host listen addresses
# --server-name - Server name
# --server-aliases - Server aliases (defaults to '*')
# --allow-remote-connections - Whether to allow remote connections or to require local connections
# --disable - Whether to render the app's virtual hosts with a .disabled prefix
# --disable-http - Whether to render the app's HTTP virtual host with a .disabled prefix
# --disable-https - Whether to render the app's HTTPS virtual host with a .disabled prefix
# --http-port - HTTP port number
# --https-port - HTTPS port number
# --move-htaccess - Move .htaccess files to a common place so they can be loaded during Apache startup (only allowed when type is not defined)
# --additional-configuration - Additional vhost configuration (no default)
# --additional-http-configuration - Additional HTTP vhost configuration (no default)
# --additional-https-configuration - Additional HTTPS vhost configuration (no default)
# --before-vhost-configuration - Configuration to add before the <VirtualHost> directive (no default)
# --allow-override - Whether to allow .htaccess files (only allowed when --move-htaccess is set to 'no' and type is not defined)
# --document-root - Path to document root directory
# --extra-directory-configuration - Extra configuration for the document root directory
# --proxy-address - Address where to proxy requests
# --proxy-configuration - Extra configuration for the proxy
# --proxy-http-configuration - Extra configuration for the proxy HTTP vhost
# --proxy-https-configuration - Extra configuration for the proxy HTTPS vhost
# Returns:
# true if the configuration was enabled, false otherwise
########################
ensure_apache_app_configuration_exists() {
local -r app="${1:?missing app}"
# Default options
local type=""
local -a hosts=("127.0.0.1" "_default_")
local server_name="www.example.com" # Default ServerName in httpd.conf
local -a server_aliases=("*")
local allow_remote_connections="yes"
local disable="no"
local disable_http="no"
local disable_https="no"
local move_htaccess="yes"
# Template variables defaults
export additional_configuration=""
export additional_http_configuration=""
export additional_https_configuration=""
export before_vhost_configuration=""
export allow_override="All"
export document_root="${BITNAMI_ROOT_DIR}/${app}"
export extra_directory_configuration=""
export default_http_port="${APACHE_HTTP_PORT_NUMBER:-"$APACHE_DEFAULT_HTTP_PORT_NUMBER"}"
export default_https_port="${APACHE_HTTPS_PORT_NUMBER:-"$APACHE_DEFAULT_HTTPS_PORT_NUMBER"}"
export http_port="$default_http_port"
export https_port="$default_https_port"
export proxy_address=""
export proxy_configuration=""
export proxy_http_configuration=""
export proxy_https_configuration=""
# Validate arguments
local var_name
shift
while [[ "$#" -gt 0 ]]; do
case "$1" in
--hosts \
| --server-aliases)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
shift
read -r -a "${var_name?}" <<< "$1"
;;
--disable \
| --disable-http \
| --disable-https \
)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
export "${var_name}=yes"
;;
--type \
| --server-name \
| --allow-remote-connections \
| --http-port \
| --https-port \
| --move-htaccess \
| --additional-configuration \
| --additional-http-configuration \
| --additional-https-configuration \
| --before-vhost-configuration \
| --allow-override \
| --document-root \
| --extra-directory-configuration \
| --proxy-address \
| --proxy-configuration \
| --proxy-http-configuration \
| --proxy-https-configuration \
)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
shift
export "${var_name}=${1}"
;;
*)
echo "Invalid command line flag $1" >&2
return 1
;;
esac
shift
done
# Construct listen ports configuration (only to add when using non-standard ports)
export http_listen_configuration=""
export https_listen_configuration=""
[[ "$http_port" != "$default_http_port" ]] && http_listen_configuration="Listen ${http_port}"
[[ "$https_port" != "$default_https_port" ]] && https_listen_configuration="Listen ${https_port}"
# Construct host string in the format of "host1:port1[ host2:port2[ ...]]"
export http_listen_addresses=""
export https_listen_addresses=""
for host in "${hosts[@]}"; do
http_listen="${host}:${http_port}"
https_listen="${host}:${https_port}"
[[ -z "${http_listen_addresses:-}" ]] && http_listen_addresses="$http_listen" || http_listen_addresses="${http_listen_addresses} ${http_listen}"
[[ -z "${https_listen_addresses:-}" ]] && https_listen_addresses="$https_listen" || https_listen_addresses="${https_listen_addresses} ${https_listen}"
done
# Construct ServerName/ServerAlias block
export server_name_configuration=""
if ! is_empty_value "${server_name:-}"; then
server_name_configuration="ServerName ${server_name}"
fi
if [[ "${#server_aliases[@]}" -gt 0 ]]; then
server_name_configuration+=$'\n'"ServerAlias ${server_aliases[*]}"
fi
# App .htaccess support (only when type is not defined)
export htaccess_include
[[ -z "$type" || "$type" = "php" ]] && is_boolean_yes "$move_htaccess" && apache_replace_htaccess_files "$app" --document-root "$document_root"
if [[ -z "$type" || "$type" = "php" ]] && [[ -f "${APACHE_HTACCESS_DIR}/${app}-htaccess.conf" ]]; then
allow_override="None"
htaccess_include="Include \"${APACHE_HTACCESS_DIR}/${app}-htaccess.conf\""
else
# allow_override is already set to the expected value
htaccess_include=""
fi
# ACL configuration
export acl_configuration
if is_boolean_yes "$allow_remote_connections"; then
acl_configuration="Require all granted"
else
acl_configuration="$(cat <<EOF
Require local
ErrorDocument 403 "For security reasons, this URL is only accessible using localhost (127.0.0.1) as the hostname."
# AuthType Basic
# AuthName ${app}
# AuthUserFile "${APACHE_BASE_DIR}/users"
# Require valid-user
EOF
)"
fi
# Indent configurations
server_name_configuration="$(indent $'\n'"$server_name_configuration" 2)"
additional_configuration="$(indent $'\n'"$additional_configuration" 2)"
additional_http_configuration="$(indent $'\n'"$additional_http_configuration" 2)"
additional_https_configuration="$(indent $'\n'"$additional_https_configuration" 2)"
htaccess_include="$(indent $'\n'"$htaccess_include" 2)"
acl_configuration=""$(indent $'\n'"$acl_configuration" 4)
extra_directory_configuration="$(indent $'\n'"$extra_directory_configuration" 4)"
proxy_configuration="$(indent $'\n'"$proxy_configuration" 2)"
proxy_http_configuration="$(indent $'\n'"$proxy_http_configuration" 2)"
proxy_https_configuration="$(indent $'\n'"$proxy_https_configuration" 2)"
# Render templates
# We remove lines that are empty or contain only newspaces with 'sed', so the resulting file looks better
local template_name="app"
[[ -n "$type" && "$type" != "php" ]] && template_name="app-${type}"
local -r template_dir="${BITNAMI_ROOT_DIR}/scripts/apache/bitnami-templates"
local http_vhost="${APACHE_VHOSTS_DIR}/${app}-vhost.conf"
local https_vhost="${APACHE_VHOSTS_DIR}/${app}-https-vhost.conf"
local -r disable_suffix=".disabled"
( is_boolean_yes "$disable" || is_boolean_yes "$disable_http" ) && http_vhost+="$disable_suffix"
( is_boolean_yes "$disable" || is_boolean_yes "$disable_https" ) && https_vhost+="$disable_suffix"
if is_file_writable "$http_vhost"; then
# Create file with root group write privileges, so it can be modified in non-root containers
[[ ! -f "$http_vhost" ]] && touch "$http_vhost" && chmod g+rw "$http_vhost"
render-template "${template_dir}/${template_name}-http-vhost.conf.tpl" | sed '/^\s*$/d' > "$http_vhost"
elif [[ ! -f "$http_vhost" ]]; then
error "Could not create virtual host for ${app} at '${http_vhost}'. Check permissions and ownership for parent directories."
return 1
else
warn "The ${app} virtual host file '${http_vhost}' is not writable. Configurations based on environment variables will not be applied for this file."
fi
if is_file_writable "$https_vhost"; then
# Create file with root group write privileges, so it can be modified in non-root containers
[[ ! -f "$https_vhost" ]] && touch "$https_vhost" && chmod g+rw "$https_vhost"
render-template "${template_dir}/${template_name}-https-vhost.conf.tpl" | sed '/^\s*$/d' > "$https_vhost"
elif [[ ! -f "$https_vhost" ]]; then
error "Could not create virtual host for ${app} at '${https_vhost}'. Check permissions and ownership for parent directories."
return 1
else
warn "The ${app} virtual host file '${https_vhost}' is not writable. Configurations based on environment variables will not be applied for this file."
fi
}
########################
# Ensure an Apache application configuration does not exist anymore (in virtual hosts format)
# Globals:
# *
# Arguments:
# $1 - App name
# Returns:
# true if the configuration was disabled, false otherwise
########################
ensure_apache_app_configuration_not_exists() {
local -r app="${1:?missing app}"
local -r http_vhost="${APACHE_VHOSTS_DIR}/${app}-vhost.conf"
local -r https_vhost="${APACHE_VHOSTS_DIR}/${app}-https-vhost.conf"
local -r disable_suffix=".disabled"
# Note that 'rm -f' will not fail if the files don't exist
# However if we lack permissions to remove the file, it will result in a non-zero exit code, as expected by this function
rm -f "$http_vhost" "$https_vhost" "${http_vhost}${disable_suffix}" "${https_vhost}${disable_suffix}"
}
########################
# Ensure Apache loads the configuration for an application in a URL prefix
# Globals:
# APACHE_*
# Arguments:
# $1 - App name
# Flags:
# --type - Application type, which has an effect on what configuration template will be used, allowed values: php, (empty)
# --allow-remote-connections - Whether to allow remote connections or to require local connections
# --move-htaccess - Move .htaccess files to a common place so they can be loaded during Apache startup (only allowed when type is not defined)
# --prefix - URL prefix from where it will be accessible (i.e. /myapp)
# --additional-configuration - Additional vhost configuration (no default)
# --allow-override - Whether to allow .htaccess files (only allowed when --move-htaccess is set to 'no' and type is not defined)
# --document-root - Path to document root directory
# --extra-directory-configuration - Extra configuration for the document root directory
# Returns:
# true if the configuration was enabled, false otherwise
########################
ensure_apache_prefix_configuration_exists() {
local -r app="${1:?missing app}"
# Default options
local type=""
local allow_remote_connections="yes"
local move_htaccess="yes"
local prefix="/${app}"
# Template variables defaults
export additional_configuration=""
export allow_override="All"
export document_root="${BITNAMI_ROOT_DIR}/${app}"
export extra_directory_configuration=""
# Validate arguments
local var_name
shift
while [[ "$#" -gt 0 ]]; do
case "$1" in
--type \
| --allow-remote-connections \
| --move-htaccess \
| --prefix \
| --additional-configuration \
| --allow-override \
| --document-root \
| --extra-directory-configuration \
)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
shift
declare "${var_name}=${1}"
;;
*)
echo "Invalid command line flag $1" >&2
return 1
;;
esac
shift
done
# App .htaccess support (only when type is not defined)
export htaccess_include
[[ -z "$type" || "$type" = "php" ]] && is_boolean_yes "$move_htaccess" && apache_replace_htaccess_files "$app" --document-root "$document_root"
if [[ -z "$type" || "$type" = "php" ]] && [[ -f "${APACHE_HTACCESS_DIR}/${app}-htaccess.conf" ]]; then
allow_override="None"
htaccess_include="Include \"${APACHE_HTACCESS_DIR}/${app}-htaccess.conf\""
else
# allow_override is already set to the expected value
htaccess_include=""
fi
# ACL configuration
export acl_configuration
if is_boolean_yes "$allow_remote_connections"; then
acl_configuration="Require all granted"
else
acl_configuration="$(cat <<EOF
Require local
ErrorDocument 403 "For security reasons, this URL is only accessible using localhost (127.0.0.1) as the hostname."
# AuthType Basic
# AuthName ${app}
# AuthUserFile "${APACHE_BASE_DIR}/users"
# Require valid-user
EOF
)"
fi
# Prefix configuration
export prefix_conf="Alias ${prefix} \"${document_root}\""
# Indent configurations
acl_configuration="$(indent $'\n'"$acl_configuration" 2)"
extra_directory_configuration="$(indent $'\n'"$extra_directory_configuration" 2)"
# Render templates
# We remove lines that are empty or contain only newspaces with 'sed', so the resulting file looks better
local template_name="app"
[[ -n "$type" && "$type" != "php" ]] && template_name="app-${type}"
local -r template_dir="${BITNAMI_ROOT_DIR}/scripts/apache/bitnami-templates"
local -r prefix_file="${APACHE_CONF_DIR}/bitnami/${app}.conf"
if is_file_writable "$prefix_file"; then
# Create file with root group write privileges, so it can be modified in non-root containers
[[ ! -f "$prefix_file" ]] && touch "$prefix_file" && chmod g+rw "$prefix_file"
render-template "${template_dir}/${template_name}-prefix.conf.tpl" | sed '/^\s*$/d' > "$prefix_file"
ensure_apache_configuration_exists "Include \"$prefix_file\""
elif [[ ! -f "$prefix_file" ]]; then
error "Could not create web server configuration file for ${app} at '${prefix_file}'. Check permissions and ownership for parent directories."
return 1
else
warn "The ${app} web server configuration file '${prefix_file}' is not writable. Configurations based on environment variables will not be applied for this file."
fi
}
########################
# Ensure Apache application configuration is updated with the runtime configuration (i.e. ports)
# Globals:
# *
# Arguments:
# $1 - App name
# Flags:
# --hosts - Host listen addresses
# --server-name - Server name
# --server-aliases - Server aliases
# --enable-http - Enable HTTP app configuration (if not enabled already)
# --enable-https - Enable HTTPS app configuration (if not enabled already)
# --disable-http - Disable HTTP app configuration (if not disabled already)
# --disable-https - Disable HTTPS app configuration (if not disabled already)
# --http-port - HTTP port number
# --https-port - HTTPS port number
# Returns:
# true if the configuration was updated, false otherwise
########################
apache_update_app_configuration() {
local -r app="${1:?missing app}"
# Default options
local -a hosts=("127.0.0.1" "_default_")
local server_name="www.example.com" # Default ServerName in httpd.conf
local -a server_aliases=()
local enable_http="no"
local enable_https="no"
local disable_http="no"
local disable_https="no"
export default_http_port="${APACHE_HTTP_PORT_NUMBER:-"$APACHE_DEFAULT_HTTP_PORT_NUMBER"}"
export default_https_port="${APACHE_HTTPS_PORT_NUMBER:-"$APACHE_DEFAULT_HTTPS_PORT_NUMBER"}"
export http_port="$default_http_port"
export https_port="$default_https_port"
local var_name
# Validate arguments
local var_name
shift
while [[ "$#" -gt 0 ]]; do
case "$1" in
--hosts \
| --server-aliases)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
shift
read -r -a "${var_name?}" <<< "$1"
;;
# Common flags
--enable-http \
| --enable-https \
| --disable-http \
| --disable-https \
)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
declare "${var_name}=yes"
;;
--server-name \
| --http-port \
| --https-port \
)
var_name="$(echo "$1" | sed -e "s/^--//" -e "s/-/_/g")"
shift
declare "${var_name}=${1}"
;;
*)
echo "Invalid command line flag $1" >&2
return 1
;;
esac
shift
done
# Construct host string in the format of "host1:port1[ host2:port2[ ...]]"
export http_listen_addresses=""
export https_listen_addresses=""
for host in "${hosts[@]}"; do
http_listen="${host}:${http_port}"
https_listen="${host}:${https_port}"
[[ -z "${http_listen_addresses:-}" ]] && http_listen_addresses="$http_listen" || http_listen_addresses="${http_listen_addresses} ${http_listen}"
[[ -z "${https_listen_addresses:-}" ]] && https_listen_addresses="$https_listen" || https_listen_addresses="${https_listen_addresses} ${https_listen}"
done
# Update configuration
local -r http_vhost="${APACHE_VHOSTS_DIR}/${app}-vhost.conf"
local -r https_vhost="${APACHE_VHOSTS_DIR}/${app}-https-vhost.conf"
local -r disable_suffix=".disabled"
# Helper function to avoid duplicating code
update_common_vhost_config() {
local -r vhost_file="${1:?missing virtual host}"
# Update ServerName
if ! is_empty_value "${server_name:-}"; then
replace_in_file "$vhost_file" "^(\s*ServerName\s+).*" "\1${server_name}"
fi
# Update ServerAlias
if [[ "${#server_aliases[@]}" -gt 0 ]]; then
replace_in_file "$vhost_file" "^(\s*ServerAlias\s+).*" "\1${server_aliases[*]}"
fi
}
# Disable and enable configuration files
rename_conf_file() {
local -r origin="$1"
local -r destination="$2"
if is_file_writable "$origin" && is_file_writable "$destination"; then
warn "Could not rename virtual host file '${origin}' to '${destination}' due to lack of permissions."
else
mv "$origin" "$destination"
fi
}
is_boolean_yes "$disable_http" && [[ -e "$http_vhost" ]] && rename_conf_file "${http_vhost}${disable_suffix}" "$http_vhost"
is_boolean_yes "$disable_https" && [[ -e "$https_vhost" ]] && rename_conf_file "${https_vhost}${disable_suffix}" "$https_vhost"
is_boolean_yes "$enable_http" && [[ -e "${http_vhost}${disable_suffix}" ]] && rename_conf_file "${http_vhost}${disable_suffix}" "$http_vhost"
is_boolean_yes "$enable_https" && [[ -e "${https_vhost}${disable_suffix}" ]] && rename_conf_file "${https_vhost}${disable_suffix}" "$https_vhost"
# Update only configuration files without the '.disabled' suffix
if [[ -e "$http_vhost" ]]; then
if is_file_writable "$http_vhost"; then
update_common_vhost_config "$http_vhost"
# Update vhost-specific config (listen port and addresses)
replace_in_file "$http_vhost" "^Listen .*" "Listen ${http_port}"
replace_in_file "$http_vhost" "^<VirtualHost\s.*>$" "<VirtualHost ${http_listen_addresses}>"
else
warn "The ${app} virtual host file '${http_vhost}' is not writable. Configurations based on environment variables will not be applied for this file."
fi
fi
if [[ -e "$https_vhost" ]]; then
if is_file_writable "$https_vhost"; then
update_common_vhost_config "$https_vhost"
# Update vhost-specific config (listen port and addresses)
replace_in_file "$https_vhost" "^Listen .*" "Listen ${https_port}"
replace_in_file "$https_vhost" "^<VirtualHost\s.*>$" "<VirtualHost ${https_listen_addresses}>"
else
warn "The ${app} virtual host file '${https_vhost}' is not writable. Configurations based on environment variables will not be applied for this file."
fi
fi
}
########################
# Create a password file for basic authentication and restrict its permissions
# Globals:
# *
# Arguments:
# $1 - file
# $2 - username
# $3 - password
# Returns:
# true if the configuration was updated, false otherwise
########################
apache_create_password_file() {
local -r file="${1:?missing file}"
local -r username="${2:?missing username}"
local -r password="${3:?missing password}"
"${APACHE_BIN_DIR}/htpasswd" -bc "$file" "$username" "$password"
am_i_root && configure_permissions_ownership "$file" --file-mode "600" --user "$APACHE_DAEMON_USER" --group "$APACHE_DAEMON_GROUP"
}

View File

@@ -0,0 +1,541 @@
#!/bin/bash
#
# Bitnami Drupal library
# shellcheck disable=SC1091
# Load Generic Libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/libnet.sh
. /opt/bitnami/scripts/libvalidations.sh
. /opt/bitnami/scripts/libversion.sh
. /opt/bitnami/scripts/libpersistence.sh
. /opt/bitnami/scripts/libwebserver.sh
# Load database library
if [[ -f /opt/bitnami/scripts/libmysqlclient.sh ]]; then
. /opt/bitnami/scripts/libmysqlclient.sh
elif [[ -f /opt/bitnami/scripts/libmysql.sh ]]; then
. /opt/bitnami/scripts/libmysql.sh
elif [[ -f /opt/bitnami/scripts/libmariadb.sh ]]; then
. /opt/bitnami/scripts/libmariadb.sh
fi
########################
# Validate settings in DRUPAL_* env vars
# Globals:
# DRUPAL_*
# Arguments:
# None
# Returns:
# 0 if the validation succeeded, 1 otherwise
#########################
drupal_validate() {
debug "Validating settings in DRUPAL_* environment variables..."
local error_code=0
# Auxiliary functions
print_validation_error() {
error "$1"
error_code=1
}
check_multi_value() {
if [[ " ${2} " != *" ${!1} "* ]]; then
print_validation_error "The allowed values for ${1} are: ${2}"
fi
}
check_yes_no_value() {
if ! is_yes_no_value "${!1}" && ! is_true_false_value "${!1}"; then
print_validation_error "The allowed values for ${1} are: yes no"
fi
}
check_resolved_hostname() {
if ! is_hostname_resolved "$1"; then
warn "Hostname $1 could not be resolved. This could lead to connection issues"
fi
}
check_mounted_file() {
if [[ -n "${!1:-}" ]] && ! [[ -f "${!1:-}" ]]; then
print_validation_error "The variable ${1} is defined but the file ${!1} is not accessible or does not exist"
fi
}
check_valid_port() {
local port_var="${1:?missing port variable}"
local err
if ! err="$(validate_port "${!port_var}")"; then
print_validation_error "An invalid port was specified in the environment variable ${port_var}: ${err}."
fi
}
# Warn users in case the configuration file is not writable
is_file_writable "$DRUPAL_CONF_FILE" || warn "The Drupal configuration file '${DRUPAL_CONF_FILE}' is not writable. Configurations based on environment variables will not be applied for this file."
# Validate user inputs
! is_empty_value "$DRUPAL_SKIP_BOOTSTRAP" && check_yes_no_value "DRUPAL_SKIP_BOOTSTRAP"
! is_empty_value "$DRUPAL_DATABASE_PORT_NUMBER" && check_valid_port "DRUPAL_DATABASE_PORT_NUMBER"
! is_empty_value "$DRUPAL_DATABASE_HOST" && check_resolved_hostname "$DRUPAL_DATABASE_HOST"
check_mounted_file "DRUPAL_DATABASE_TLS_CA_FILE"
# Validate database credentials
if is_boolean_yes "$ALLOW_EMPTY_PASSWORD"; then
warn "You set the environment variable ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}. For safety reasons, do not use this flag in a production environment."
else
for empty_env_var in "DRUPAL_DATABASE_PASSWORD" "DRUPAL_PASSWORD"; do
is_empty_value "${!empty_env_var}" && print_validation_error "The ${empty_env_var} environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow a blank password. This is only recommended for development environments."
done
fi
# Validate SMTP credentials
if ! is_empty_value "$DRUPAL_SMTP_HOST"; then
for empty_env_var in "DRUPAL_SMTP_USER" "DRUPAL_SMTP_PASSWORD"; do
is_empty_value "${!empty_env_var}" && warn "The ${empty_env_var} environment variable is empty or not set."
done
is_empty_value "$DRUPAL_SMTP_PORT_NUMBER" && print_validation_error "The DRUPAL_SMTP_PORT_NUMBER environment variable is empty or not set."
! is_empty_value "$DRUPAL_SMTP_PORT_NUMBER" && check_valid_port "DRUPAL_SMTP_PORT_NUMBER"
! is_empty_value "$DRUPAL_SMTP_PROTOCOL" && check_multi_value "DRUPAL_SMTP_PROTOCOL" "standard tls ssl"
fi
# Check that the web server is properly set up
web_server_validate || print_validation_error "Web server validation failed"
return "$error_code"
}
########################
# Ensure Drupal is initialized
# Globals:
# DRUPAL_*
# Arguments:
# None
# Returns:
# None
#########################
drupal_initialize() {
# Update Drupal configuration via mounted configuration files and environment variables
if is_file_writable "$DRUPAL_CONF_FILE"; then
# Enable mounted configuration files
if [[ -f "$DRUPAL_MOUNTED_CONF_FILE" ]]; then
info "Found mounted Drupal configuration file '${DRUPAL_MOUNTED_CONF_FILE}', copying to '${DRUPAL_CONF_FILE}'"
cp "$DRUPAL_MOUNTED_CONF_FILE" "$DRUPAL_CONF_FILE"
return
fi
fi
# Check if Drupal has already been initialized and persisted in a previous run
local -r app_name="drupal"
if ! is_app_initialized "$app_name"; then
info "Trying to connect to the database server"
drupal_wait_for_db_connection "$DRUPAL_DATABASE_HOST" "$DRUPAL_DATABASE_PORT_NUMBER" "$DRUPAL_DATABASE_NAME" "$DRUPAL_DATABASE_USER" "$DRUPAL_DATABASE_PASSWORD"
# Ensure the Drupal base directory exists and has proper permissions
info "Configuring file permissions for Drupal"
ensure_dir_exists "$DRUPAL_VOLUME_DIR"
# Use daemon:root ownership for compatibility when running as a non-root user
am_i_root && configure_permissions_ownership "$DRUPAL_VOLUME_DIR" -d "775" -f "664" -u "$WEB_SERVER_DAEMON_USER" -g "root"
if ! is_boolean_yes "$DRUPAL_SKIP_BOOTSTRAP"; then
# Perform initial bootstrapping for Drupal
info "Installing Drupal site"
drupal_site_install
if ! is_empty_value "$DRUPAL_ENABLE_MODULES"; then
info "Enabling Drupal modules"
drupal_enable_modules
fi
if ! is_empty_value "$DRUPAL_SMTP_HOST"; then
info "Configuring SMTP"
drupal_configure_smtp
fi
info "Flushing Drupal cache"
drupal_flush_cache
else
info "An already initialized Drupal database was provided, configuration will be skipped"
if is_empty_value "$DRUPAL_DATABASE_TLS_CA_FILE"; then
drupal_set_database_settings
else
drupal_set_database_ssl_settings
fi
# Drupal expects a directory for storing site configuration
# For more info see https://www.drupal.org/docs/configuration-management
drupal_create_config_directory
# Drupal needs a hash value to build one-time login links, cancel links, form tokens, etc.
drupal_set_hash_salt
drupal_update_database
fi
info "Persisting Drupal installation"
persist_app "$app_name" "$DRUPAL_DATA_TO_PERSIST"
else
info "Restoring persisted Drupal installation"
restore_persisted_app "$app_name" "$DRUPAL_DATA_TO_PERSIST"
info "Trying to connect to the database server"
db_host="$(drupal_database_conf_get 'host')"
db_port="$(drupal_database_conf_get 'port')"
db_name="$(drupal_database_conf_get 'database')"
db_user="$(drupal_database_conf_get 'username')"
db_pass="$(drupal_database_conf_get 'password')"
drupal_wait_for_db_connection "$db_host" "$db_port" "$db_name" "$db_user" "$db_pass"
drupal_update_database
fi
# Avoid exit code of previous commands to affect the result of this function
true
}
########################
# Get a database entry from the Drupal configuration file (settings.php)
# Globals:
# DRUPAL_*
# Arguments:
# $1 - Key
# Returns:
# None
#########################
drupal_database_conf_get() {
local -r key="${1:?key missing}"
debug "Getting ${key} from Drupal database configuration"
grep -E "^\s*'${key}' =>" "$DRUPAL_CONF_FILE" | grep -E -o "=> '.*'" | cut -f2 -d\'
}
########################
# Add or modify an entry in the Drupal configuration file (settings.php)
# Globals:
# DRUPAL_*
# Arguments:
# $1 - PHP variable name
# $2 - Value to assign to the PHP variable
# $3 - Whether the value is a literal, or if instead it should be quoted (default: no)
# Returns:
# None
#########################
drupal_conf_set() {
local -r key="${1:?key missing}"
local -r value="${2:?value missing}"
local -r is_literal="${3:-no}"
debug "Setting ${key} to '${value}' in Drupal configuration (literal: ${is_literal})"
# Sanitize key (sed does not support fixed string substitutions)
local sanitized_pattern
sanitized_pattern="^(#\s*)?$(sed 's/[]\[^$.*/]/\\&/g' <<< "$key")\s*=.*"
local entry
is_boolean_yes "$is_literal" && entry="${key} = $value;" || entry="${key} = '$value';"
# Check if the configuration exists in the file
if grep -q -E "$sanitized_pattern" "$DRUPAL_CONF_FILE"; then
# It exists, so replace the line
replace_in_file "$DRUPAL_CONF_FILE" "$sanitized_pattern" "$entry"
else
echo "$entry" >> "$DRUPAL_CONF_FILE"
fi
}
########################
# Wait until the database is accessible with the currently-known credentials
# Globals:
# *
# Arguments:
# $1 - database host
# $2 - database port
# $3 - database name
# $4 - database username
# $5 - database user password (optional)
# Returns:
# true if the database connection succeeded, false otherwise
#########################
drupal_wait_for_db_connection() {
local -r db_host="${1:?missing database host}"
local -r db_port="${2:?missing database port}"
local -r db_name="${3:?missing database name}"
local -r db_user="${4:?missing database user}"
local -r db_pass="${5:-}"
check_mysql_connection() {
echo "SELECT 1" | mysql_remote_execute "$db_host" "$db_port" "$db_name" "$db_user" "$db_pass"
}
if ! retry_while "check_mysql_connection"; then
error "Could not connect to the database"
return 1
fi
}
########################
# Drupal Site Install
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_site_install() {
is_empty_value "$DRUPAL_DATABASE_TLS_CA_FILE" || drupal_set_database_ssl_settings
(
# Unfortunately there is no way to disable mail sending via sendmail when installing Drupal
# The "hack" consists of overriding the sendmail path to an executable that does nothing (i.e. "/bin/true")
# This is also what Drush is doing in their CI
PHP_OPTIONS="-d sendmail_path=$(which true)"
export PHP_OPTIONS
drush_execute "site:install" \
"--db-url=mysql://${DRUPAL_DATABASE_USER}:${DRUPAL_DATABASE_PASSWORD}@${DRUPAL_DATABASE_HOST}:${DRUPAL_DATABASE_PORT_NUMBER}/${DRUPAL_DATABASE_NAME}" \
"--account-name=${DRUPAL_USERNAME}" \
"--account-mail=${DRUPAL_EMAIL}" \
"--account-pass=${DRUPAL_PASSWORD}" \
"--site-name=${DRUPAL_SITE_NAME}" \
"--site-mail=${DRUPAL_EMAIL}" \
"-y" "$DRUPAL_PROFILE"
)
# When Drupal settings are patched to allow SSL database connections, the database settings block is duplicated
# after the installation with Drush
is_empty_value "$DRUPAL_DATABASE_TLS_CA_FILE" || drupal_remove_duplicated_database_settings
# Restrict permissions of the configuration file to keep the site secure
if am_i_root; then
configure_permissions_ownership "$DRUPAL_CONF_FILE" -u "root" -g "$WEB_SERVER_DAEMON_USER" -f "644"
fi
}
########################
# Create Drupal sync configuration directory (DRUPAL_SKIP_BOOTSTRAP only)
# Globals:
# DRUPAL_BASE_DIR
# Arguments:
# None
# Returns:
# None
#########################
drupal_create_config_directory() {
local config_sync_dir="${DRUPAL_CONFIG_SYNC_DIR:-}"
if is_empty_value "$config_sync_dir"; then
config_sync_dir="${DRUPAL_BASE_DIR}/sites/default/files/config_$(generate_random_string -t alphanumeric -c 16)"
fi
ensure_dir_exists "$config_sync_dir"
drupal_conf_set "\$settings['config_sync_directory']" "$config_sync_dir"
}
########################
# Create Drupal hash salt value (DRUPAL_SKIP_BOOTSTRAP only)
# Globals:
# DRUPAL_HASH_SALT
# Arguments:
# None
# Returns:
# None
#########################
drupal_set_hash_salt() {
local hash_salt="${DRUPAL_HASH_SALT:-}"
if is_empty_value "$hash_salt"; then
hash_salt="$(generate_random_string -t alphanumeric -c 32)"
fi
drupal_conf_set "\$settings['hash_salt']" "$hash_salt"
}
########################
# Execute Drush Tool
# Globals:
# *
# Arguments:
# $@ - Arguments to pass to the Drush tool
# Returns:
# None
#########################
drush_execute() {
if am_i_root; then
debug_execute gosu "$WEB_SERVER_DAEMON_USER" drush "--root=${DRUPAL_BASE_DIR}" "$@"
else
debug_execute drush "--root=${DRUPAL_BASE_DIR}" "$@"
fi
}
########################
# Execute Drush Tool to set a config option
# Globals:
# *
# Arguments:
# $1 - config group
# $2 - config key
# $3 - config value
# Returns:
# None
#########################
drush_config_set() {
local -r group="${1:?missing config group}"
local -r key="${2:?missing config key}"
local -r value="${3:-}"
drush_execute "config-set" "--yes" "$group" "$key" "$value"
}
########################
# Drupal enable modules
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_enable_modules() {
local -a modules
read -r -a modules <<< "${DRUPAL_ENABLE_MODULES/,/ }"
[[ "${#modules[@]}" -gt 0 ]] || return 0
drush_execute "pm:enable" "--yes" "${modules[@]}"
}
########################
# Drupal configure SMTP
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_configure_smtp() {
drush_execute "pm:enable" "--yes" "smtp"
drush_config_set "system.mail" "interface.default" "SMTPMailSystem"
drush_config_set "smtp.settings" "smtp_on" "1"
drush_config_set "smtp.settings" "smtp_host" "$DRUPAL_SMTP_HOST"
drush_config_set "smtp.settings" "smtp_port" "$DRUPAL_SMTP_PORT_NUMBER"
drush_config_set "smtp.settings" "smtp_protocol" "$DRUPAL_SMTP_PROTOCOL"
drush_config_set "smtp.settings" "smtp_username" "$DRUPAL_SMTP_USER"
drush_config_set "smtp.settings" "smtp_password" "$DRUPAL_SMTP_PASSWORD"
drush_config_set "smtp.settings" "smtp_from" "$DRUPAL_EMAIL"
drush_config_set "smtp.settings" "smtp_fromname" "$DRUPAL_SITE_NAME"
}
########################
# Drupal flush cache
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_flush_cache() {
drush_execute "cache:rebuild"
}
########################
# Drupal update database
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_update_database() {
debug 'Upgrading Drupal database with drush...'
drush_execute "updatedb"
}
########################
# Drupal set database SSL settings
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_set_database_ssl_settings() {
cat >>"$DRUPAL_CONF_FILE" <<EOF
\$databases['default']['default'] = array ( // Database block with SSL support
'database' => '${DRUPAL_DATABASE_NAME}',
'username' => '${DRUPAL_DATABASE_USER}',
'password' => '${DRUPAL_DATABASE_PASSWORD}',
'prefix' => '',
'host' => '${DRUPAL_DATABASE_HOST}',
'port' => '${DRUPAL_DATABASE_PORT_NUMBER}',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
'pdo' => array (
PDO::MYSQL_ATTR_SSL_CA => '${DRUPAL_DATABASE_TLS_CA_FILE}',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => 0
)
);
EOF
}
########################
# Drupal set database non-SSL settings (DRUPAL_SKIP_BOOTSTRAP only)
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_set_database_settings() {
cat >>"$DRUPAL_CONF_FILE" <<EOF
\$databases['default']['default'] = array ( // Database block with SSL support
'database' => '${DRUPAL_DATABASE_NAME}',
'username' => '${DRUPAL_DATABASE_USER}',
'password' => '${DRUPAL_DATABASE_PASSWORD}',
'prefix' => '',
'host' => '${DRUPAL_DATABASE_HOST}',
'port' => '${DRUPAL_DATABASE_PORT_NUMBER}',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);
EOF
}
########################
# Drupal remove duplicated database block from settings file
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_remove_duplicated_database_settings() {
local -r first_line_block=$'\$databases\[\'default\'\]\[\'default\'\] = array \($'
local -r last_line_block='\);'
remove_in_file "$DRUPAL_CONF_FILE" "${first_line_block}/,/${last_line_block}"
}
########################
# Drupal fix htaccess warning protection.
# Drupal checks for the htaccess file to prevent malicious attacks
# Globals:
# *
# Arguments:
# None
# Returns:
# None
#########################
drupal_fix_htaccess_warning_protection() {
local -r files_dir="${DRUPAL_BASE_DIR}/sites/default/files/"
local -r htaccess_file="${files_dir}/.htaccess"
ensure_dir_exists "$files_dir"
cat <<EOF >"$htaccess_file"
# Recommended protections: https://www.drupal.org/forum/newsletters/security-advisories-for-drupal-core/2013-11-20/sa-core-2013-003-drupal-core
# Turn off all options we don\'t need.
Options -Indexes -ExecCGI -Includes -MultiViews
# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
# Override the handler again if we\'re run later in the evaluation list.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>
# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php7.c>
php_flag engine off
</IfModule>
EOF
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,257 @@
#!/bin/bash
#
# Bitnami PHP library
# shellcheck disable=SC1091
# Load Generic Libraries
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/libfile.sh
. /opt/bitnami/scripts/libservice.sh
. /opt/bitnami/scripts/libvalidations.sh
. /opt/bitnami/scripts/libwebserver.sh
########################
# Add or modify an entry in the main PHP configuration file (php.ini)
# Globals:
# PHP_CONF_FILE
# Arguments:
# $1 - Key
# $2 - Value
# $3 - File to modify (default: $PHP_CONF_FILE)
# Returns:
# None
#########################
php_conf_set() {
local -r key="${1:?key missing}"
local -r value="${2:?value missing}"
local -r file="${3:-"$PHP_CONF_FILE"}"
local pattern="^[; ]*${key}\s*=.*$"
if [[ "$key" = "extension" || "$key" = "zend_extension" ]]; then
# The "extension" property works a bit different for PHP, as there is one per module to be included, meaning it is additive unlike other configurations
# Because of that, we first check if the extension was defined in the file to replace the proper entry
pattern="^[; ]*${key}\s*=\s*[\"]?${value}(\.so)?[\"]?\s*$"
fi
local -r entry="${key} = ${value}"
if is_file_writable "$file"; then
# Not using the ini-file tool since it does not play well with php.ini
if grep -q -E "$pattern" "$file"; then
replace_in_file "$file" "$pattern" "$entry"
else
cat >> "$file" <<< "$entry"
fi
else
warn "The PHP configuration file '${file}' is not writable. The '${key}' option will not be configured."
fi
}
########################
# Ensure PHP is initialized
# Globals:
# PHP_*
# Arguments:
# None
# Returns:
# None
#########################
php_initialize() {
# Configure PHP options based on the runtime environment
info "Configuring PHP options"
php_set_runtime_config "$PHP_CONF_FILE"
# PHP-FPM configuration
! is_empty_value "$PHP_FPM_LISTEN_ADDRESS" && info "Setting PHP-FPM listen option" && php_conf_set "listen" "$PHP_FPM_LISTEN_ADDRESS" "${PHP_CONF_DIR}/php-fpm.d/www.conf"
# Avoid exit code of previous commands to affect the result of this function
true
}
########################
# Set PHP runtime options, based on user-provided environment variables
# Globals:
# PHP_*
# Arguments:
# None
# Returns:
# None
#########################
php_set_runtime_config() {
local -r conf_file="${1:?missing conf file}"
! is_empty_value "$PHP_DATE_TIMEZONE" && info "Setting PHP date.timezone option" && php_conf_set date.timezone "$PHP_DATE_TIMEZONE" "$conf_file"
! is_empty_value "$PHP_ENABLE_OPCACHE" && info "Setting PHP opcache.enable option" && php_conf_set opcache.enable "$PHP_ENABLE_OPCACHE" "$conf_file"
! is_empty_value "$PHP_EXPOSE_PHP" && info "Setting PHP expose_php option" && php_conf_set expose_php "$PHP_EXPOSE_PHP" "$conf_file"
! is_empty_value "$PHP_MAX_EXECUTION_TIME" && info "Setting PHP max_execution_time option" && php_conf_set max_execution_time "$PHP_MAX_EXECUTION_TIME" "$conf_file"
! is_empty_value "$PHP_MAX_INPUT_TIME" && info "Setting PHP max_input_time option" && php_conf_set max_input_time "$PHP_MAX_INPUT_TIME" "$conf_file"
! is_empty_value "$PHP_MAX_INPUT_VARS" && info "Setting PHP max_input_vars option" && php_conf_set max_input_vars "$PHP_MAX_INPUT_VARS" "$conf_file"
! is_empty_value "$PHP_MEMORY_LIMIT" && info "Setting PHP memory_limit option" && php_conf_set memory_limit "$PHP_MEMORY_LIMIT" "$conf_file"
! is_empty_value "$PHP_POST_MAX_SIZE" && info "Setting PHP post_max_size option" && php_conf_set post_max_size "$PHP_POST_MAX_SIZE" "$conf_file"
! is_empty_value "$PHP_UPLOAD_MAX_FILESIZE" && info "Setting PHP upload_max_filesize option" && php_conf_set upload_max_filesize "$PHP_UPLOAD_MAX_FILESIZE" "$conf_file"
true
}
########################
# Convert a yes/no value to a PHP boolean
# Globals:
# None
# Arguments:
# $1 - yes/no value
# Returns:
# None
#########################
php_convert_to_boolean() {
local -r value="${1:?missing value}"
is_boolean_yes "$value" && echo "true" || echo "false"
}
########################
# Execute/run PHP code and print to stdout
# Globals:
# None
# Stdin:
# Code to execute
# Arguments:
# $1..$n - Input arguments to script
# Returns:
# None
#########################
php_execute_print_output() {
local php_cmd
# Obtain the command specified via stdin
php_cmd="$(</dev/stdin)"
debug "Executing PHP code:\n${php_cmd}"
php -- "$@" <<< "<?php ${php_cmd}"
}
########################
# Execute/run PHP code
# Globals:
# None
# Stdin:
# Code to execute
# Arguments:
# $1..$n - Input arguments to script
# Returns:
# None
#########################
php_execute() {
debug_execute php_execute_print_output "$@"
}
########################
# Execute/run PHP code and print to stdout
# Globals:
# None
# Stdin:
# Code to execute
# Arguments:
# $1..$n - Input arguments to script
# Returns:
# None
#########################
php_execute_print_output() {
local php_cmd
# Obtain the command specified via stdin
php_cmd="$(</dev/stdin)"
debug "Executing PHP code:\n${php_cmd}"
php -- "$@" <<< "<?php ${php_cmd}"
}
########################
# Execute/run PHP code
# Globals:
# None
# Stdin:
# Code to execute
# Arguments:
# $1..$n - Input arguments to script
# Returns:
# None
#########################
php_execute() {
debug_execute php_execute_print_output "$@"
}
########################
# Stop PHP-FPM
# Globals:
# PHP_FPM_PID_FILE
# Arguments:
# $1 - Signal (default: SIGTERM)
# Returns:
# None
#########################
php_fpm_stop() {
local -r signal="${1:-}"
is_php_fpm_not_running && return
stop_service_using_pid "$PHP_FPM_PID_FILE" "$signal"
}
########################
# Reload PHP-FPM configuration
# Globals:
# PHP_FPM_PID_FILE
# Arguments:
# None
# Returns:
# None
#########################
php_fpm_reload() {
php_fpm_stop "USR2"
}
########################
# Check if PHP-FPM is enabled for the current Bitnami installation
# Globals:
# None
# Arguments:
# None
# Returns:
# true if PHP-FPM is enabled, false otherwise
########################
is_php_fpm_enabled() {
if [[ "$(web_server_type)" = "apache" ]]; then
# If mod_php is enabled, then PHP-FPM is cannot be
if apachectl -M | grep -q -E "php[0-9]?_module"; then
false
else
true
fi
else
# Assume PHP-FPM is enabled with any other configuration (i.e. NGINX)
true
fi
}
########################
# Check if PHP-FPM is running
# Globals:
# PHP_FPM_PID_FILE
# Arguments:
# None
# Returns:
# true if PHP-FPM is running, false otherwise
########################
is_php_fpm_running() {
local pid
pid="$(get_pid_from_file "$PHP_FPM_PID_FILE")"
if [[ -n "$pid" ]]; then
is_service_running "$pid"
else
false
fi
}
########################
# Check if PHP-FPM is running
# Globals:
# PHP_FPM_PID_FILE
# Arguments:
# None
# Returns:
# true PHP-FPM is not running, false otherwise
########################
is_php_fpm_not_running() {
! is_php_fpm_running
}

View File

@@ -0,0 +1,125 @@
#!/bin/bash
#
# Environment configuration for mysql
# The values for all environment variables will be set in the below order of precedence
# 1. Custom environment variables defined below after Bitnami defaults
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
# 3. Environment variables overridden via external files using *_FILE variables (see below)
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
# Load logging library
# shellcheck disable=SC1090,SC1091
. /opt/bitnami/scripts/liblog.sh
export BITNAMI_ROOT_DIR="/opt/bitnami"
export BITNAMI_VOLUME_DIR="/bitnami"
# Logging configuration
export MODULE="${MODULE:-mysql}"
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
# variable will be overridden with the value specified in that file
mysql_env_vars=(
MYSQL_CLIENT_FLAVOR
ALLOW_EMPTY_PASSWORD
MYSQL_CLIENT_DATABASE_AUTHENTICATION_PLUGIN
MYSQL_CLIENT_DATABASE_HOST
MYSQL_CLIENT_DATABASE_PORT_NUMBER
MYSQL_CLIENT_DATABASE_ROOT_USER
MYSQL_CLIENT_DATABASE_ROOT_PASSWORD
MYSQL_CLIENT_CREATE_DATABASE_NAME
MYSQL_CLIENT_CREATE_DATABASE_USER
MYSQL_CLIENT_CREATE_DATABASE_PASSWORD
MYSQL_CLIENT_CREATE_DATABASE_CHARACTER_SET
MYSQL_CLIENT_CREATE_DATABASE_COLLATE
MYSQL_CLIENT_CREATE_DATABASE_PRIVILEGES
MYSQL_CLIENT_ENABLE_SSL_WRAPPER
MYSQL_CLIENT_ENABLE_SSL
MYSQL_CLIENT_SSL_CA_FILE
MYSQL_CLIENT_SSL_CERT_FILE
MYSQL_CLIENT_SSL_KEY_FILE
MYSQL_CLIENT_EXTRA_FLAGS
MARIADB_AUTHENTICATION_PLUGIN
MARIADB_HOST
MARIADB_PORT_NUMBER
MARIADB_ROOT_USER
MARIADB_ROOT_PASSWORD
)
for env_var in "${mysql_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
if [[ -n "${!file_env_var:-}" ]]; then
if [[ -r "${!file_env_var:-}" ]]; then
export "${env_var}=$(< "${!file_env_var}")"
unset "${file_env_var}"
else
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
fi
fi
done
unset mysql_env_vars
export MYSQL_CLIENT_FLAVOR="${MYSQL_CLIENT_FLAVOR:-mariadb}"
export DB_FLAVOR="$MYSQL_CLIENT_FLAVOR"
# Paths
export DB_BASE_DIR="${BITNAMI_ROOT_DIR}/mysql"
export DB_VOLUME_DIR="${BITNAMI_VOLUME_DIR}/mysql"
export DB_DATA_DIR="${DB_VOLUME_DIR}/data"
export DB_BIN_DIR="${DB_BASE_DIR}/bin"
export DB_SBIN_DIR="${DB_BASE_DIR}/bin"
export DB_CONF_DIR="${DB_BASE_DIR}/conf"
export DB_LOGS_DIR="${DB_BASE_DIR}/logs"
export DB_TMP_DIR="${DB_BASE_DIR}/tmp"
export DB_CONF_FILE="${DB_CONF_DIR}/my.cnf"
export DB_PID_FILE="${DB_TMP_DIR}/mysqld.pid"
export DB_SOCKET_FILE="${DB_TMP_DIR}/mysql.sock"
export PATH="${DB_SBIN_DIR}:${DB_BIN_DIR}:/opt/bitnami/common/bin:${PATH}"
# System users (when running with a privileged user)
export DB_DAEMON_USER="mysql"
export DB_DAEMON_GROUP="mysql"
# MySQL client configuration
export ALLOW_EMPTY_PASSWORD="${ALLOW_EMPTY_PASSWORD:-no}"
MYSQL_CLIENT_DATABASE_AUTHENTICATION_PLUGIN="${MYSQL_CLIENT_DATABASE_AUTHENTICATION_PLUGIN:-"${MARIADB_AUTHENTICATION_PLUGIN:-}"}"
export MYSQL_CLIENT_DATABASE_AUTHENTICATION_PLUGIN="${MYSQL_CLIENT_DATABASE_AUTHENTICATION_PLUGIN:-}"
export DB_AUTHENTICATION_PLUGIN="$MYSQL_CLIENT_DATABASE_AUTHENTICATION_PLUGIN"
MYSQL_CLIENT_DATABASE_HOST="${MYSQL_CLIENT_DATABASE_HOST:-"${MARIADB_HOST:-}"}"
export MYSQL_CLIENT_DATABASE_HOST="${MYSQL_CLIENT_DATABASE_HOST:-mariadb}"
export DB_HOST="$MYSQL_CLIENT_DATABASE_HOST"
MYSQL_CLIENT_DATABASE_PORT_NUMBER="${MYSQL_CLIENT_DATABASE_PORT_NUMBER:-"${MARIADB_PORT_NUMBER:-}"}"
export MYSQL_CLIENT_DATABASE_PORT_NUMBER="${MYSQL_CLIENT_DATABASE_PORT_NUMBER:-3306}"
export DB_PORT_NUMBER="$MYSQL_CLIENT_DATABASE_PORT_NUMBER"
MYSQL_CLIENT_DATABASE_ROOT_USER="${MYSQL_CLIENT_DATABASE_ROOT_USER:-"${MARIADB_ROOT_USER:-}"}"
export MYSQL_CLIENT_DATABASE_ROOT_USER="${MYSQL_CLIENT_DATABASE_ROOT_USER:-root}"
export DB_ROOT_USER="$MYSQL_CLIENT_DATABASE_ROOT_USER" # only used during the first initialization
MYSQL_CLIENT_DATABASE_ROOT_PASSWORD="${MYSQL_CLIENT_DATABASE_ROOT_PASSWORD:-"${MARIADB_ROOT_PASSWORD:-}"}"
export MYSQL_CLIENT_DATABASE_ROOT_PASSWORD="${MYSQL_CLIENT_DATABASE_ROOT_PASSWORD:-}"
export DB_ROOT_PASSWORD="$MYSQL_CLIENT_DATABASE_ROOT_PASSWORD" # only used during the first initialization
export MYSQL_CLIENT_CREATE_DATABASE_NAME="${MYSQL_CLIENT_CREATE_DATABASE_NAME:-}"
export DB_CREATE_DATABASE_NAME="$MYSQL_CLIENT_CREATE_DATABASE_NAME" # only used during the first initialization
export MYSQL_CLIENT_CREATE_DATABASE_USER="${MYSQL_CLIENT_CREATE_DATABASE_USER:-}"
export DB_CREATE_DATABASE_USER="$MYSQL_CLIENT_CREATE_DATABASE_USER"
export MYSQL_CLIENT_CREATE_DATABASE_PASSWORD="${MYSQL_CLIENT_CREATE_DATABASE_PASSWORD:-}"
export DB_CREATE_DATABASE_PASSWORD="$MYSQL_CLIENT_CREATE_DATABASE_PASSWORD"
export MYSQL_CLIENT_CREATE_DATABASE_CHARACTER_SET="${MYSQL_CLIENT_CREATE_DATABASE_CHARACTER_SET:-}"
export DB_CREATE_DATABASE_CHARACTER_SET="$MYSQL_CLIENT_CREATE_DATABASE_CHARACTER_SET"
export MYSQL_CLIENT_CREATE_DATABASE_COLLATE="${MYSQL_CLIENT_CREATE_DATABASE_COLLATE:-}"
export DB_CREATE_DATABASE_COLLATE="$MYSQL_CLIENT_CREATE_DATABASE_COLLATE"
export MYSQL_CLIENT_CREATE_DATABASE_PRIVILEGES="${MYSQL_CLIENT_CREATE_DATABASE_PRIVILEGES:-}"
export DB_CREATE_DATABASE_PRIVILEGES="$MYSQL_CLIENT_CREATE_DATABASE_PRIVILEGES"
export MYSQL_CLIENT_ENABLE_SSL_WRAPPER="${MYSQL_CLIENT_ENABLE_SSL_WRAPPER:-no}"
export DB_ENABLE_SSL_WRAPPER="$MYSQL_CLIENT_ENABLE_SSL_WRAPPER"
export MYSQL_CLIENT_ENABLE_SSL="${MYSQL_CLIENT_ENABLE_SSL:-no}"
export DB_ENABLE_SSL="$MYSQL_CLIENT_ENABLE_SSL"
export MYSQL_CLIENT_SSL_CA_FILE="${MYSQL_CLIENT_SSL_CA_FILE:-}"
export DB_SSL_CA_FILE="$MYSQL_CLIENT_SSL_CA_FILE"
export MYSQL_CLIENT_SSL_CERT_FILE="${MYSQL_CLIENT_SSL_CERT_FILE:-}"
export DB_SSL_CERT_FILE="$MYSQL_CLIENT_SSL_CERT_FILE"
export MYSQL_CLIENT_SSL_KEY_FILE="${MYSQL_CLIENT_SSL_KEY_FILE:-}"
export DB_SSL_KEY_FILE="$MYSQL_CLIENT_SSL_KEY_FILE"
export MYSQL_CLIENT_EXTRA_FLAGS="${MYSQL_CLIENT_EXTRA_FLAGS:-no}"
export DB_EXTRA_FLAGS="$MYSQL_CLIENT_EXTRA_FLAGS"
# Custom environment variables may be defined below

View File

@@ -0,0 +1,19 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libfs.sh
# Load MySQL Client environment variables
. /opt/bitnami/scripts/mysql-client-env.sh
for dir in "$DB_BIN_DIR" "${DB_BASE_DIR}/.bin"; do
ensure_dir_exists "$dir"
chmod g+rwX "$dir"
done

View File

@@ -0,0 +1,19 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libmysqlclient.sh
# Load MySQL Client environment variables
. /opt/bitnami/scripts/mysql-client-env.sh
# Ensure MySQL Client environment variables settings are valid
mysql_client_validate
# Ensure MySQL Client is initialized
mysql_client_initialize

View File

@@ -0,0 +1,87 @@
#!/bin/bash
#
# Environment configuration for php
# The values for all environment variables will be set in the below order of precedence
# 1. Custom environment variables defined below after Bitnami defaults
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
# 3. Environment variables overridden via external files using *_FILE variables (see below)
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
# Load logging library
# shellcheck disable=SC1090,SC1091
. /opt/bitnami/scripts/liblog.sh
export BITNAMI_ROOT_DIR="/opt/bitnami"
export BITNAMI_VOLUME_DIR="/bitnami"
# Logging configuration
export MODULE="${MODULE:-php}"
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
# variable will be overridden with the value specified in that file
php_env_vars=(
PHP_FPM_LISTEN_ADDRESS
PHP_DATE_TIMEZONE
PHP_ENABLE_OPCACHE
PHP_MAX_EXECUTION_TIME
PHP_MAX_INPUT_TIME
PHP_MAX_INPUT_VARS
PHP_MEMORY_LIMIT
PHP_POST_MAX_SIZE
PHP_UPLOAD_MAX_FILESIZE
PHP_OPCACHE_ENABLED
)
for env_var in "${php_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
if [[ -n "${!file_env_var:-}" ]]; then
if [[ -r "${!file_env_var:-}" ]]; then
export "${env_var}=$(< "${!file_env_var}")"
unset "${file_env_var}"
else
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
fi
fi
done
unset php_env_vars
# Paths
export PHP_BASE_DIR="${BITNAMI_ROOT_DIR}/php"
export PHP_BIN_DIR="${PHP_BASE_DIR}/bin"
export PHP_CONF_DIR="${PHP_BASE_DIR}/etc"
export PHP_TMP_DIR="${PHP_BASE_DIR}/var/run"
export PHP_CONF_FILE="${PHP_CONF_DIR}/php.ini"
# PHP default build-time configuration
export PHP_DEFAULT_OPCACHE_INTERNED_STRINGS_BUFFER="16" # only used at build time
export PHP_DEFAULT_OPCACHE_MEMORY_CONSUMPTION="192" # only used at build time
export PHP_DEFAULT_OPCACHE_FILE_CACHE="${PHP_TMP_DIR}/opcache_file" # only used at build time
# PHP-FPM configuration
export PHP_FPM_SBIN_DIR="${PHP_BASE_DIR}/sbin"
export PHP_FPM_LOGS_DIR="${PHP_BASE_DIR}/logs"
export PHP_FPM_LOG_FILE="${PHP_FPM_LOGS_DIR}/php-fpm.log"
export PHP_FPM_CONF_FILE="${PHP_CONF_DIR}/php-fpm.conf"
export PHP_FPM_PID_FILE="${PHP_TMP_DIR}/php-fpm.pid"
export PHP_FPM_DEFAULT_LISTEN_ADDRESS="${PHP_TMP_DIR}/www.sock" # only used at build time
export PHP_FPM_LISTEN_ADDRESS="${PHP_FPM_LISTEN_ADDRESS:-}"
export PATH="${PHP_FPM_SBIN_DIR}:${PHP_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}"
# System users (when running with a privileged user)
export PHP_FPM_DAEMON_USER="daemon"
export PHP_FPM_DAEMON_GROUP="daemon"
# PHP configuration
export PHP_DATE_TIMEZONE="${PHP_DATE_TIMEZONE:-}"
PHP_ENABLE_OPCACHE="${PHP_ENABLE_OPCACHE:-"${PHP_OPCACHE_ENABLED:-}"}"
export PHP_ENABLE_OPCACHE="${PHP_ENABLE_OPCACHE:-}"
export PHP_EXPOSE_PHP="0"
export PHP_MAX_EXECUTION_TIME="${PHP_MAX_EXECUTION_TIME:-}"
export PHP_MAX_INPUT_TIME="${PHP_MAX_INPUT_TIME:-}"
export PHP_MAX_INPUT_VARS="${PHP_MAX_INPUT_VARS:-}"
export PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:-}"
export PHP_POST_MAX_SIZE="${PHP_POST_MAX_SIZE:-}"
export PHP_UPLOAD_MAX_FILESIZE="${PHP_UPLOAD_MAX_FILESIZE:-}"
# Custom environment variables may be defined below

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/libfs.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
# PHP OPcache optimizations
php_conf_set "opcache.interned_strings_buffer" "$PHP_DEFAULT_OPCACHE_INTERNED_STRINGS_BUFFER"
php_conf_set "opcache.memory_consumption" "$PHP_DEFAULT_OPCACHE_MEMORY_CONSUMPTION"
php_conf_set "opcache.file_cache" "$PHP_DEFAULT_OPCACHE_FILE_CACHE"
# PHP-FPM configuration
php_conf_set "listen" "$PHP_FPM_DEFAULT_LISTEN_ADDRESS" "${PHP_CONF_DIR}/php-fpm.d/www.conf"
# TMP dir configuration
php_conf_set "upload_tmp_dir" "${PHP_BASE_DIR}/tmp"
php_conf_set "session.save_path" "${PHP_TMP_DIR}/session"
# Log errors to stdout for easy debugging
php_conf_set "error_log" "/dev/stderr"
# Ensure directories used by PHP-FPM exist and have proper ownership and permissions
for dir in "$PHP_CONF_DIR" "${PHP_BASE_DIR}/tmp" "$PHP_TMP_DIR" "$PHP_FPM_LOGS_DIR" "${PHP_TMP_DIR}/session"; do
ensure_dir_exists "$dir"
chmod -R g+rwX "$dir"
done
info "Disabling PHP-FPM daemon user/group configuration"
mv "${PHP_CONF_DIR}/common.conf" "${PHP_CONF_DIR}/common.conf.disabled"
touch "${PHP_CONF_DIR}/common.conf"
ln -sf "/dev/stdout" "$PHP_FPM_LOG_FILE"

View File

@@ -0,0 +1,35 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libwebserver.sh
# Load PHP-FPM environment
. /opt/bitnami/scripts/php-env.sh
# Load web server environment and functions
. "/opt/bitnami/scripts/$(web_server_type)-env.sh"
error_code=0
if is_php_fpm_enabled; then
if is_php_fpm_not_running; then
error "php-fpm is not running"
error_code=1
else
info "** Reloading PHP-FPM configuration **"
php_fpm_reload
fi
else
web_server_reload
fi
exit "$error_code"

View File

@@ -0,0 +1,17 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
/opt/bitnami/scripts/php/stop.sh
/opt/bitnami/scripts/php/start.sh

View File

@@ -0,0 +1,19 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/liblog.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
info "** Starting PHP-FPM **"
declare -a args=("--pid" "$PHP_FPM_PID_FILE" "--fpm-config" "$PHP_FPM_CONF_FILE" "-c" "$PHP_CONF_DIR" "-F")
exec "${PHP_FPM_SBIN_DIR}/php-fpm" "${args[@]}"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/libos.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
# Ensure PHP-FPM daemon user exists and required folder belongs to this user when running as 'root'
if am_i_root; then
ensure_user_exists "$PHP_FPM_DAEMON_USER" --group "$PHP_FPM_DAEMON_GROUP"
ensure_dir_exists "$PHP_TMP_DIR"
chown -R "${PHP_FPM_DAEMON_USER}:${PHP_FPM_DAEMON_GROUP}" "$PHP_TMP_DIR"
# Enable daemon configuration
if [[ ! -f "${PHP_CONF_DIR}/common.conf" ]]; then
cp "${PHP_CONF_DIR}/common.conf.disabled" "${PHP_CONF_DIR}/common.conf"
fi
fi
php_initialize
# Fix logging issue when running as root
! am_i_root || chmod o+w "$(readlink /dev/stdout)" "$(readlink /dev/stderr)"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/liblog.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
error_code=0
if is_php_fpm_not_running; then
nohup /opt/bitnami/scripts/php/run.sh >/dev/null 2>&1 &
if ! retry_while "is_php_fpm_running"; then
error "php-fpm did not start"
error_code=1
else
info "php-fpm started"
fi
else
info "php-fpm is already running"
fi
exit "$error_code"

View File

@@ -0,0 +1,21 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/liblog.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
if is_php_fpm_running; then
info "php-fpm is already running"
else
info "php-fpm is not running"
fi

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libphp.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/liblog.sh
# Load PHP-FPM environment variables
. /opt/bitnami/scripts/php-env.sh
error_code=0
if is_php_fpm_running; then
BITNAMI_QUIET=1 php_fpm_stop
if ! retry_while "is_php_fpm_not_running"; then
error "php-fpm could not be stopped"
error_code=1
else
info "php-fpm stopped"
fi
else
info "php-fpm is not running"
fi
exit "$error_code"

View File

@@ -0,0 +1,31 @@
#!/bin/bash
#
# Executes custom PHP init scripts
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries with logging functions
if [[ -f /opt/bitnami/base/functions ]]; then
. /opt/bitnami/base/functions
else
. /opt/bitnami/scripts/liblog.sh
fi
# Loop through all input files passed via stdin
read -r -a custom_init_scripts <<< "$@"
failure=0
if [[ "${#custom_init_scripts[@]}" -gt 0 ]]; then
for custom_init_script in "${custom_init_scripts[@]}"; do
[[ "$custom_init_script" != *".php" ]] && continue
info "Executing ${custom_init_script} with PHP interpreter"
php "$custom_init_script" || failure=1
[[ "$failure" -ne 0 ]] && error "Failed to execute ${custom_init_script}"
done
fi
exit "$failure"

View File

@@ -0,0 +1,36 @@
#!/bin/bash
#
# Executes custom Bash init scripts
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries with logging functions
if [[ -f /opt/bitnami/base/functions ]]; then
. /opt/bitnami/base/functions
else
. /opt/bitnami/scripts/liblog.sh
fi
# Loop through all input files passed via stdin
read -r -a custom_init_scripts <<< "$@"
failure=0
if [[ "${#custom_init_scripts[@]}" -gt 0 ]]; then
for custom_init_script in "${custom_init_scripts[@]}"; do
[[ "$custom_init_script" != *".sh" ]] && continue
if [[ -x "$custom_init_script" ]]; then
info "Executing ${custom_init_script}"
"$custom_init_script" || failure="1"
else
info "Sourcing ${custom_init_script} as it is not executable by the current user, any error may cause initialization to fail"
. "$custom_init_script"
fi
[[ "$failure" -ne 0 ]] && error "Failed to execute ${custom_init_script}"
done
fi
exit "$failure"

View File

@@ -0,0 +1,46 @@
#!/bin/bash
#
# Executes custom MySQL (.sql or .sql.gz) init scripts
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries with logging functions
if [[ -f /opt/bitnami/base/functions ]]; then
. /opt/bitnami/base/functions
else
. /opt/bitnami/scripts/liblog.sh
fi
mysql_execute() {
local -r sql_file="${1:?missing file}"
local failure=0
mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER")
if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then
mysql_cmd+=("-p${MARIADB_ROOT_PASSWORD}")
fi
if [[ "$sql_file" == *".sql" ]]; then
"${mysql_cmd[@]}" < "$sql_file" || failure=$?
elif [[ "$sql_file" == *".sql.gz" ]]; then
gunzip -c "$sql_file" | "${mysql_cmd[@]}" || failure=$?
fi
return "$failure"
}
# Loop through all input files passed via stdin
read -r -a custom_init_scripts <<< "$@"
failure=0
if [[ "${#custom_init_scripts[@]}" -gt 0 ]]; then
for custom_init_script in "${custom_init_scripts[@]}"; do
[[ ! "$custom_init_script" =~ ^.*(\.sql|\.sql\.gz)$ ]] && continue
info "Executing ${custom_init_script}"
mysql_execute "$custom_init_script" || failure=1
[[ "$failure" -ne 0 ]] && error "Failed to execute ${custom_init_script}"
done
fi
exit "$failure"

View File

@@ -0,0 +1,23 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Only execute init scripts once
if [[ ! -f "/bitnami/drupal/.user_scripts_initialized" && -d "/docker-entrypoint-init.d" ]]; then
read -r -a init_scripts <<< "$(find "/docker-entrypoint-init.d" -type f -print0 | sort -z | xargs -0)"
if [[ "${#init_scripts[@]}" -gt 0 ]] && [[ ! -f "/bitnami/drupal/.user_scripts_initialized" ]]; then
mkdir -p "/bitnami/drupal"
for init_script in "${init_scripts[@]}"; do
for init_script_type_handler in /post-init.d/*.sh; do
"$init_script_type_handler" "$init_script"
done
done
fi
touch "/bitnami/drupal/.user_scripts_initialized"
fi