From 1490bde56eb829b2d850ef8e985af343029bbd4a Mon Sep 17 00:00:00 2001 From: jknapp Date: Wed, 1 Apr 2026 12:50:54 -0700 Subject: [PATCH] Switch shared vhost from SetHandler to ProxyPassMatch for PHP-FPM SetHandler + ProxyFCGISetEnvIf doesn't work for path remapping because reqenv('SCRIPT_FILENAME') is empty when the directive evaluates with the SetHandler approach. ProxyPassMatch directly maps .php URLs to the FPM container's filesystem path, bypassing the SCRIPT_FILENAME rewrite issue entirely: ^/(.*\.php(/.*)?)$ -> fcgi://fpm:9000/home/{user}/public_html/$1 Static assets (CSS, JS, images) bypass the proxy since they don't match \.php and are served directly by Apache from the read-only mount. Tested and confirmed working on live site with WordPress (including pretty URLs via .htaccess mod_rewrite). Co-Authored-By: Claude Opus 4.6 (1M context) --- configs/shared-vhost-template.tpl | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/configs/shared-vhost-template.tpl b/configs/shared-vhost-template.tpl index b3720eb..521ae07 100644 --- a/configs/shared-vhost-template.tpl +++ b/configs/shared-vhost-template.tpl @@ -27,15 +27,11 @@ SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key - - SetHandler "proxy:fcgi://~~fpm_host~~:~~fpm_port~~" - - - # Rewrite SCRIPT_FILENAME for PHP-FPM: the shared httpd serves from - # /mnt/users/{user}/{domain}/public_html but the FPM container has - # files at /home/{user}/public_html. Use regex match with backreferences - # to reconstruct the correct path for the FPM container. - ProxyFCGISetEnvIf "reqenv('SCRIPT_FILENAME') =~ m#^/mnt/users/([^/]+)/([^/]+)/public_html(.*)#" SCRIPT_FILENAME "/home/$1/public_html$3" + # Proxy PHP requests to FPM with the correct filesystem path. + # Apache serves static files directly from /mnt/users/ (read-only mount), + # but PHP-FPM has files at /home/{user}/public_html/ (its own mount). + # ProxyPassMatch maps .php URLs directly to the FPM container's path. + ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://~~fpm_host~~:~~fpm_port~~/home/~~user~~/public_html/$1" DirectoryIndex index.php index.html index.htm