mirror of
https://github.com/devilbox/docker-php-fpm.git
synced 2025-12-10 11:01:14 +00:00
Add option to customize PHP-FPM configuration
This commit is contained in:
@@ -1,18 +1,5 @@
|
||||
[www]
|
||||
|
||||
; User and Group
|
||||
user = devilbox
|
||||
group = devilbox
|
||||
|
||||
; Ensure to listen here
|
||||
listen = 9000
|
||||
|
||||
; Keep env variables set by docker
|
||||
clear_env = no
|
||||
|
||||
; Ensure worker stdout and stderr are sent to the main error log.
|
||||
catch_workers_output = yes
|
||||
|
||||
; Pool config
|
||||
pm = dynamic
|
||||
pm.max_children = 5
|
||||
|
||||
@@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
@@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
@@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
@@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
@@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
@@ -58,6 +58,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
48
Dockerfiles/prod/data/docker-entrypoint.d/36-custom-php-fpm-files.sh
Executable file
48
Dockerfiles/prod/data/docker-entrypoint.d/36-custom-php-fpm-files.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
set -o pipefail
|
||||
|
||||
|
||||
############################################################
|
||||
# Functions
|
||||
############################################################
|
||||
|
||||
###
|
||||
### Copy PHP-FPM *.conf files from source to destination with prefix
|
||||
###
|
||||
copy_fpm_files() {
|
||||
local fpm_src="${1}"
|
||||
local fpm_dst="${2}"
|
||||
local debug="${3}"
|
||||
|
||||
if [ ! -d "${fpm_src}" ]; then
|
||||
run "mkdir -p ${fpm_src}" "${debug}"
|
||||
fi
|
||||
fpm_files="$( find "${fpm_src}" -type f -iname '*.conf' )"
|
||||
|
||||
# loop over them line by line
|
||||
IFS='
|
||||
'
|
||||
for fpm_f in ${fpm_files}; do
|
||||
fpm_name="$( basename "${fpm_f}" )"
|
||||
log "info" "PHP-FOM.conf: ${fpm_name} -> ${fpm_dst}/zzz-devilbox-${fpm_name}" "${debug}"
|
||||
run "cp ${fpm_f} ${fpm_dst}/zzz-devilbox-${fpm_name}" "${debug}"
|
||||
done
|
||||
run "find ${fpm_dst} -type f -iname '*.conf' -exec chmod 0644 \"{}\" \;" "${debug}"
|
||||
}
|
||||
|
||||
|
||||
############################################################
|
||||
# Sanity Checks
|
||||
############################################################
|
||||
|
||||
if ! command -v find >/dev/null 2>&1; then
|
||||
echo "find not found, but required."
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v basename >/dev/null 2>&1; then
|
||||
echo "basename not found, but required."
|
||||
exit 1
|
||||
fi
|
||||
@@ -21,6 +21,9 @@ CONFIG_DIR="/docker-entrypoint.d"
|
||||
# php.ini.d directory
|
||||
PHP_INI_DIR="/usr/local/etc/php/conf.d"
|
||||
|
||||
# php-fpm conf.d directory
|
||||
PHP_FPM_DIR="/usr/local/etc/php-fpm.d"
|
||||
|
||||
# This is the log file for any mail related functions
|
||||
PHP_MAIL_LOG="/var/log/mail.log"
|
||||
|
||||
@@ -33,6 +36,9 @@ FPM_LOG_DIR="/var/log/php"
|
||||
# Custom ini dir (to be copied to actual ini dir)
|
||||
PHP_CUST_INI_DIR="/etc/php-custom.d"
|
||||
|
||||
# Custom PHP-FPM dir (to be copied to actual FPM conf dir)
|
||||
PHP_CUST_FPM_DIR="/etc/php-fpm-custom.d"
|
||||
|
||||
# Supervisord config directory
|
||||
SUPERVISOR_CONFD="/etc/supervisor/conf.d"
|
||||
|
||||
@@ -140,6 +146,12 @@ supervisor_add_service "php-fpm" "/usr/local/sbin/php-fpm" "${SUPERVISOR_CONFD}
|
||||
copy_ini_files "${PHP_CUST_INI_DIR}" "${PHP_INI_DIR}" "${DEBUG_LEVEL}"
|
||||
|
||||
|
||||
###
|
||||
### Copy custom PHP-FPM *.conf files
|
||||
###
|
||||
copy_fpm_files "${PHP_CUST_FPM_DIR}" "${PHP_FPM_DIR}" "${DEBUG_LEVEL}"
|
||||
|
||||
|
||||
###
|
||||
### Startup
|
||||
###
|
||||
|
||||
@@ -303,6 +303,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -307,6 +307,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -21,6 +21,9 @@ CONFIG_DIR="/docker-entrypoint.d"
|
||||
# php.ini.d directory
|
||||
PHP_INI_DIR="/usr/local/etc/php/conf.d"
|
||||
|
||||
# php-fpm conf.d directory
|
||||
PHP_FPM_DIR="/usr/local/etc/php-fpm.d"
|
||||
|
||||
# This is the log file for any mail related functions
|
||||
PHP_MAIL_LOG="/var/log/mail.log"
|
||||
|
||||
@@ -33,6 +36,9 @@ FPM_LOG_DIR="/var/log/php"
|
||||
# Custom ini dir (to be copied to actual ini dir)
|
||||
PHP_CUST_INI_DIR="/etc/php-custom.d"
|
||||
|
||||
# Custom PHP-FPM dir (to be copied to actual FPM conf dir)
|
||||
PHP_CUST_FPM_DIR="/etc/php-fpm-custom.d"
|
||||
|
||||
# Supervisord config directory
|
||||
SUPERVISOR_CONFD="/etc/supervisor/conf.d"
|
||||
|
||||
@@ -140,6 +146,12 @@ supervisor_add_service "php-fpm" "/usr/local/sbin/php-fpm" "${SUPERVISOR_CONFD}
|
||||
copy_ini_files "${PHP_CUST_INI_DIR}" "${PHP_INI_DIR}" "${DEBUG_LEVEL}"
|
||||
|
||||
|
||||
###
|
||||
### Copy custom PHP-FPM *.conf files
|
||||
###
|
||||
copy_fpm_files "${PHP_CUST_FPM_DIR}" "${PHP_FPM_DIR}" "${DEBUG_LEVEL}"
|
||||
|
||||
|
||||
###
|
||||
### mysqldump-secure
|
||||
###
|
||||
|
||||
@@ -97,16 +97,20 @@ Have a look at the following table to see all offered volumes for each Docker im
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Image</th>
|
||||
<th width="200">Volumes</th>
|
||||
<th width="220">Volumes</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="4"><strong>prod</strong><br/><br/><strong>work</strong></td>
|
||||
<td rowspan="5"><strong>prod</strong><br/><br/><strong>work</strong></td>
|
||||
<td><code>/etc/php-custom.d</code></td>
|
||||
<td>Mount this directory into your host computer and add custom <code>\*.ini</code> files in order to alter php behaviour.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>/etc/php-fpm-custom.d</code></td>
|
||||
<td>Mount this directory into your host computer and add custom PHP-FOM <code>\*.conf</code> files in order to alter PHP-FPM behaviour.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>/etc/php-modules.d</code></td>
|
||||
<td>Mount this directory into your host computer and add custo <code>\*.so</code> files in order to add your php modules.<br/><br/><strong>Note:</strong>Your should then also provide a custom <code>\*.ini</code> file in order to actually load your custom provided module.</td>
|
||||
|
||||
@@ -60,6 +60,7 @@ COPY ./data/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
### Volumes
|
||||
###
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /var/log/php
|
||||
VOLUME /var/mail
|
||||
|
||||
@@ -194,6 +194,7 @@ COPY ./data/sudo-devilbox /etc/sudoers.d/devilbox
|
||||
###
|
||||
VOLUME /etc/bash-custom.d
|
||||
VOLUME /etc/php-custom.d
|
||||
VOLUME /etc/php-fpm-custom.d
|
||||
VOLUME /etc/php-modules.d
|
||||
VOLUME /shared/backups
|
||||
VOLUME /var/log/php
|
||||
|
||||
@@ -71,8 +71,8 @@ run "sleep 10"
|
||||
###
|
||||
### Check correct PHP-FPM user
|
||||
###
|
||||
if ! docker_exec "${did}" "ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | head -1 | grep devilbox"; then
|
||||
docker_exec "${did}" "ps aux"
|
||||
if ! docker_exec "${did}" "ps auxw | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | head -1 | grep devilbox"; then
|
||||
docker_exec "${did}" "ps auxw"
|
||||
|
||||
# Shutdown
|
||||
docker_stop "${ndid}" || true
|
||||
@@ -82,8 +82,8 @@ if ! docker_exec "${did}" "ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
if ! docker_exec "${did}" "ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | tail -1 | grep devilbox"; then
|
||||
docker_exec "${did}" "ps aux"
|
||||
if ! docker_exec "${did}" "ps auxw | grep 'php-fpm: pool' | grep -v grep | awk '{ print \$1 }' | tail -1 | grep devilbox"; then
|
||||
docker_exec "${did}" "ps auxw"
|
||||
|
||||
# Shutdown
|
||||
docker_stop "${ndid}" || true
|
||||
|
||||
181
tests/prod/06-test-mount-custom_fpm_conf.sh
Executable file
181
tests/prod/06-test-mount-custom_fpm_conf.sh
Executable file
@@ -0,0 +1,181 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
set -o pipefail
|
||||
|
||||
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
||||
|
||||
IMAGE="${1}"
|
||||
VERSION="${2}"
|
||||
FLAVOUR="${3}"
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
. "${CWD}/../.lib.sh"
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Tests
|
||||
############################################################
|
||||
|
||||
###
|
||||
### Test Nginx with PHP-FPM
|
||||
###
|
||||
WWW_PORT="23254"
|
||||
DOC_ROOT_HOST="$( mktemp -d )"
|
||||
DOC_ROOT_CONT="/var/www/default"
|
||||
|
||||
CONFIG_HOST="$( mktemp -d )"
|
||||
CONFIG_CONT="/etc/nginx/conf.d"
|
||||
|
||||
PHP_CNF_HOST="$( mktemp -d )"
|
||||
PHP_CNF_CONT="/etc/php-fpm-custom.d"
|
||||
|
||||
CONTAINER="nginx:stable"
|
||||
|
||||
echo "php_admin_value[post_max_size] = 17M" > "${PHP_CNF_HOST}/post.conf"
|
||||
echo "<?php phpinfo();" > "${DOC_ROOT_HOST}/index.php"
|
||||
|
||||
# Fix mount permissions
|
||||
chmod 0777 "${CONFIG_HOST}"
|
||||
chmod 0777 "${PHP_CNF_HOST}"
|
||||
chmod 0777 "${DOC_ROOT_HOST}"
|
||||
chmod 0644 "${DOC_ROOT_HOST}/index.php"
|
||||
|
||||
# Pull container
|
||||
run "docker pull ${CONTAINER}"
|
||||
|
||||
# Start PHP-FPM
|
||||
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -v ${DOC_ROOT_HOST}:${DOC_ROOT_CONT} -v ${PHP_CNF_HOST}:${PHP_CNF_CONT}" )"
|
||||
name="$( docker_name "${did}" )"
|
||||
|
||||
# Nginx.conf
|
||||
{
|
||||
echo "server {"
|
||||
echo " server_name _;"
|
||||
echo " listen 80;"
|
||||
echo " root ${DOC_ROOT_CONT};"
|
||||
echo " index index.php;"
|
||||
echo " location ~* \.php\$ {"
|
||||
echo " fastcgi_index index.php;"
|
||||
echo " fastcgi_pass ${name}:9000;"
|
||||
echo " include fastcgi_params;"
|
||||
echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"
|
||||
echo " fastcgi_param SCRIPT_NAME \$fastcgi_script_name;"
|
||||
echo " }"
|
||||
echo "}"
|
||||
} > "${CONFIG_HOST}/php.conf"
|
||||
|
||||
|
||||
# Start Nginx
|
||||
ndid="$( docker_run "${CONTAINER}" "-v ${DOC_ROOT_HOST}:${DOC_ROOT_CONT} -v ${CONFIG_HOST}:${CONFIG_CONT} -p ${WWW_PORT}:80 --link ${name}" )"
|
||||
|
||||
# Wait for both containers to be up and running
|
||||
run "sleep 10"
|
||||
|
||||
# Check entrypoint
|
||||
if ! run "docker logs ${did} | grep 'post.conf'"; then
|
||||
docker_logs "${ndid}" || true
|
||||
docker_logs "${did}" || true
|
||||
docker_stop "${ndid}" || true
|
||||
docker_stop "${did}" || true
|
||||
rm -rf "${DOC_ROOT_HOST}"
|
||||
rm -rf "${CONFIG_HOST}"
|
||||
rm -rf "${PHP_CNF_HOST}"
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check PHP connectivity
|
||||
if ! run "curl -q -4 http://127.0.0.1:${WWW_PORT}/index.php >/dev/null 2>&1"; then
|
||||
# Info
|
||||
run "netstat -tuln"
|
||||
run "curl -4 http://127.0.0.1:${WWW_PORT}/index.php" || true
|
||||
run "curl -6 http://127.0.0.1:${WWW_PORT}/index.php" || true
|
||||
run "docker ps --no-trunc"
|
||||
docker_exec "${ndid}" "nginx -t"
|
||||
|
||||
# Show logs
|
||||
docker_logs "${ndid}" || true
|
||||
docker_logs "${did}" || true
|
||||
|
||||
# Ensure file is available
|
||||
docker_exec "${ndid}" "ls -la ${DOC_ROOT_CONT}/"
|
||||
docker_exec "${did}" "ls -la ${DOC_ROOT_CONT}/"
|
||||
|
||||
docker_exec "${ndid}" "cat ${DOC_ROOT_CONT}/index.php"
|
||||
docker_exec "${did}" "cat ${DOC_ROOT_CONT}/index.php"
|
||||
|
||||
# Nginx configuration
|
||||
docker_exec "${ndid}" "cat ${CONFIG_CONT}/php.conf"
|
||||
|
||||
# Shutdown
|
||||
docker_stop "${ndid}" || true
|
||||
docker_stop "${did}" || true
|
||||
rm -rf "${DOC_ROOT_HOST}"
|
||||
rm -rf "${CONFIG_HOST}"
|
||||
rm -rf "${PHP_CNF_HOST}"
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check modified php-fpm.conf
|
||||
if ! docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\" | grep '17M'"; then
|
||||
# Info
|
||||
docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\""
|
||||
|
||||
# Show logs
|
||||
docker_logs "${ndid}" || true
|
||||
docker_logs "${did}" || true
|
||||
|
||||
# Shutdown
|
||||
docker_stop "${ndid}" || true
|
||||
docker_stop "${did}" || true
|
||||
rm -rf "${DOC_ROOT_HOST}"
|
||||
rm -rf "${CONFIG_HOST}"
|
||||
rm -rf "${PHP_CNF_HOST}"
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check modified php-fpm.conf
|
||||
if ! run "curl -q -4 http://127.0.0.1:${WWW_PORT}/index.php 2>/dev/null | grep post_max_size | grep '17M'"; then
|
||||
# Info
|
||||
run "netstat -tuln"
|
||||
run "curl -4 http://127.0.0.1:${WWW_PORT}/index.php" || true
|
||||
run "curl -6 http://127.0.0.1:${WWW_PORT}/index.php" || true
|
||||
run "docker ps --no-trunc"
|
||||
docker_exec "${ndid}" "nginx -t"
|
||||
|
||||
# Show logs
|
||||
docker_logs "${ndid}" || true
|
||||
docker_logs "${did}" || true
|
||||
|
||||
# Ensure file is available
|
||||
docker_exec "${ndid}" "ls -la ${DOC_ROOT_CONT}/"
|
||||
docker_exec "${did}" "ls -la ${DOC_ROOT_CONT}/"
|
||||
|
||||
docker_exec "${ndid}" "cat ${DOC_ROOT_CONT}/index.php"
|
||||
docker_exec "${did}" "cat ${DOC_ROOT_CONT}/index.php"
|
||||
|
||||
# Nginx configuration
|
||||
docker_exec "${ndid}" "cat ${CONFIG_CONT}/php.conf"
|
||||
|
||||
# Shutdown
|
||||
docker_stop "${ndid}" || true
|
||||
docker_stop "${did}" || true
|
||||
rm -rf "${DOC_ROOT_HOST}"
|
||||
rm -rf "${CONFIG_HOST}"
|
||||
rm -rf "${PHP_CNF_HOST}"
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Cleanup
|
||||
docker_stop "${did}"
|
||||
docker_stop "${ndid}"
|
||||
rm -rf "${DOC_ROOT_HOST}"
|
||||
rm -rf "${CONFIG_HOST}"
|
||||
rm -rf "${PHP_CNF_HOST}"
|
||||
Reference in New Issue
Block a user