Files
cloud-apache-container/scripts/create-php-config.sh
jknapp e20f5620d7
All checks were successful
Cloud Apache Container / Build-and-Push (74) (push) Successful in 1m19s
Cloud Apache Container / Build-and-Push (80) (push) Successful in 2m5s
Cloud Apache Container / Build-and-Push (81) (push) Successful in 2m9s
Cloud Apache Container / Build-and-Push (82) (push) Successful in 2m15s
Cloud Apache Container / Build-and-Push (83) (push) Successful in 2m11s
Cloud Apache Container / Build-and-Push (84) (push) Successful in 2m12s
Cloud Apache Container / Build-and-Push (85) (push) Successful in 2m14s
Cloud Apache Container / Build-FPM-Images (74) (push) Successful in 2m18s
Cloud Apache Container / Build-FPM-Images (80) (push) Successful in 2m14s
Cloud Apache Container / Build-FPM-Images (81) (push) Successful in 2m51s
Cloud Apache Container / Build-FPM-Images (82) (push) Successful in 1m27s
Cloud Apache Container / Build-FPM-Images (83) (push) Successful in 2m0s
Cloud Apache Container / Build-FPM-Images (84) (push) Successful in 2m12s
Cloud Apache Container / Build-FPM-Images (85) (push) Successful in 2m6s
Cloud Apache Container / Build-Shared-httpd (push) Successful in 1m13s
Fix DOCUMENT_ROOT for PHP-FPM in shared httpd mode
WordPress plugins like WordFence use $_SERVER['DOCUMENT_ROOT'] to locate
config/log files. With ProxyPassMatch, Apache sends its own mount path
(/mnt/users/...) as DOCUMENT_ROOT, which doesn't exist in the FPM
container.

ProxyFCGISetEnvIf can't override DOCUMENT_ROOT when using ProxyPassMatch
(Apache sets it after the directive evaluates). Instead, set it via the
FPM pool config's env[] directive which takes precedence.

create-php-config.sh now adds env[DOCUMENT_ROOT] = /home/$user/public_html
when in TCP listen mode (shared httpd), giving PHP the correct path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 13:04:53 -07:00

59 lines
1.6 KiB
Bash

#!/bin/bash
rm /etc/php-fpm.d/www.conf
FPM_LISTEN=${FPM_LISTEN:-/run/php-fpm/www.sock}
# Determine listen directive and ownership based on socket vs TCP
if echo "$FPM_LISTEN" | grep -q '/'; then
# Unix socket mode (standalone — Apache and FPM in same container)
listen_directive="$FPM_LISTEN"
listen_owner_block="listen.owner = apache
listen.group = apache"
env_block=""
else
# TCP port mode (shared httpd — FPM in separate container)
listen_directive="0.0.0.0:${FPM_LISTEN}"
listen_owner_block=""
# Override DOCUMENT_ROOT so PHP plugins (e.g., WordFence) that use
# $_SERVER['DOCUMENT_ROOT'] find files at the FPM container's path,
# not the shared httpd's /mnt/users/ mount path.
env_block="env[DOCUMENT_ROOT] = /home/$user/public_html"
fi
cat <<EOF > /etc/php-fpm.d/$user.conf
[$user]
user = $user
group = $user
listen = ${listen_directive}
${listen_owner_block}
pm = ${PHP_FPM_PM}
pm.max_children = ${PHP_FPM_MAX_CHILDREN}
pm.max_requests = ${PHP_FPM_MAX_REQUESTS}
pm.process_idle_timeout = ${PHP_FPM_PROCESS_IDLE_TIMEOUT}
; Settings used when pm = dynamic (fallback if user overrides FPM_PM)
pm.start_servers = ${PHP_FPM_START_SERVERS}
pm.min_spare_servers = ${PHP_FPM_MIN_SPARE}
pm.max_spare_servers = ${PHP_FPM_MAX_SPARE}
; Health check endpoints
ping.path = /fpm-ping
ping.response = pong
pm.status_path = /fpm-status
slowlog = /home/$user/logs/php-fpm/slowlog
request_slowlog_timeout = 3s
php_admin_value[error_log] = /home/$user/logs/php-fpm/error.log
php_admin_flag[log_errors] = on
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
${env_block}
EOF
exit 0