Skip to content

Commit e9e941a

Browse files
Fix systemic 502 risk: align new PHP-FPM pool ownership with nginx's actual user
php_install_script() installed php{ver}-fpm but never checked whether nginx's worker user (the 'user' directive in nginx.conf) matched the new pool's listen.owner/listen.group (package defaults: www-data on Debian, apache/nginx on RHEL). On this server nginx runs as 'nginx', but PHP 8.5's pool (installed after the phpMyAdmin installer's one-time owner-fix loop had already run for other versions) kept www-data - causing 'connect() ... failed (13: Permission denied)' and 502 Bad Gateway for every site on PHP 8.5, including phpMyAdmin. Now detects nginx's actual user and aligns listen.owner/listen.group for every newly-installed PHP version on both Debian and RHEL-family, so this can't recur for future App Store PHP installs.
1 parent b57cb73 commit e9e941a

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

panel/routes/os_utils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,37 @@ def nginx_install_script(channel='stable'):
120120
def php_install_script(ver):
121121
"""PHP install script for all distros"""
122122
os_info = get_os()
123+
# After installing PHP-FPM, align the pool's listen.owner/listen.group
124+
# with nginx's actual worker user. Package defaults (www-data on
125+
# Debian/Ubuntu, apache/nginx on RHEL) may not match what nginx is
126+
# actually configured to run as - a mismatch causes nginx to fail
127+
# connecting to the FPM socket with "(13: Permission denied)", i.e.
128+
# every website on this PHP version returns 502 Bad Gateway.
129+
fix_pool_owner = (
130+
'NGINX_USER=$(grep -oP "^user\\s+\\K\\S+" /etc/nginx/nginx.conf 2>/dev/null | tr -d ";" | head -1); '
131+
'NGINX_USER=${NGINX_USER:-www-data}; '
132+
f'for POOL in /etc/php/{ver}/fpm/pool.d/www.conf /etc/php-fpm.d/www.conf; do '
133+
' [ -f "$POOL" ] || continue; '
134+
' grep -q "^listen.owner" "$POOL" && sed -i "s|^listen.owner.*|listen.owner = $NGINX_USER|" "$POOL" || echo "listen.owner = $NGINX_USER" >> "$POOL"; '
135+
' grep -q "^listen.group" "$POOL" && sed -i "s|^listen.group.*|listen.group = $NGINX_USER|" "$POOL" || echo "listen.group = $NGINX_USER" >> "$POOL"; '
136+
'done'
137+
)
123138
if os_info['family'] == 'debian':
124139
return (
125140
f'add-apt-repository -y ppa:ondrej/php 2>/dev/null; '
126141
f'{pkg_update()} && '
127142
f'{pkg_install(f"php{ver} php{ver}-fpm php{ver}-common php{ver}-mysql php{ver}-xml php{ver}-curl php{ver}-mbstring php{ver}-zip php{ver}-gd php{ver}-bcmath php{ver}-intl php{ver}-soap php{ver}-redis")} && '
128-
f'systemctl enable php{ver}-fpm && systemctl start php{ver}-fpm'
143+
f'systemctl enable php{ver}-fpm && systemctl start php{ver}-fpm && '
144+
f'{fix_pool_owner} && systemctl restart php{ver}-fpm'
129145
)
130146
elif os_info['family'] in ('rhel','fedora'):
131147
return (
132148
f'dnf install -y https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %rhel).rpm 2>/dev/null; '
133149
f'dnf module reset php -y 2>/dev/null; '
134150
f'dnf module enable php:remi-{ver} -y 2>/dev/null; '
135151
f'{pkg_install(f"php php-fpm php-common php-mysql php-xml php-curl php-mbstring php-zip php-gd php-bcmath php-intl php-soap")} && '
136-
f'systemctl enable php-fpm && systemctl start php-fpm'
152+
f'systemctl enable php-fpm && systemctl start php-fpm && '
153+
f'{fix_pool_owner} && systemctl restart php-fpm'
137154
)
138155
return f'{pkg_install(f"php{ver}-fpm")} && systemctl enable php{ver}-fpm'
139156

0 commit comments

Comments
 (0)