autodetect correct php version and adjust configs as needed

This commit is contained in:
Matthew Saunders Brown 2024-07-26 14:26:55 -07:00
parent c68942f0aa
commit 48871ee4fd
5 changed files with 19 additions and 14 deletions

View File

@ -57,7 +57,7 @@ if /bin/grep -q "^$username:" /etc/passwd; then
if [[ -n "$fpmmax" ]]; then if [[ -n "$fpmmax" ]]; then
vhost::set-phpVersion vhost::set-phpVersion
if [[ -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then if [[ -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
sed -i "s|pm.max_children.*|pm.max_children = $fpmmax|g" /etc/php/8.1/fpm/pool.d/$username.conf sed -i "s|pm.max_children.*|pm.max_children = $fpmmax|g" /etc/php/$phpVersion/fpm/pool.d/$username.conf
else else
echo "ERROR: PHP config for $username does not exist." echo "ERROR: PHP config for $username does not exist."
exit 1 exit 1

View File

@ -39,7 +39,7 @@
RewriteCond %{REQUEST_URI} ^/cgi-bin/.* RewriteCond %{REQUEST_URI} ^/cgi-bin/.*
RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT] RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT]
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
</Macro> </Macro>
@ -52,7 +52,7 @@
</IfDefine> </IfDefine>
DocumentRoot /srv/www/$vhost/html/$subdomain DocumentRoot /srv/www/$vhost/html/$subdomain
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
</Macro> </Macro>
@ -78,7 +78,7 @@
</Location> </Location>
</IfDefine> </IfDefine>
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
@ -93,7 +93,7 @@
RewriteCond %{REQUEST_URI} ^/cgi-bin/.* RewriteCond %{REQUEST_URI} ^/cgi-bin/.*
RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT] RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT]
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
SSLEngine on SSLEngine on
SSLCertificateFile /etc/ssl/letsencrypt/$vhost.pem SSLCertificateFile /etc/ssl/letsencrypt/$vhost.pem
@ -129,7 +129,7 @@
</Location> </Location>
</IfDefine> </IfDefine>
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
@ -139,7 +139,7 @@
</IfDefine> </IfDefine>
DocumentRoot /srv/www/$vhost/html/$subdomain DocumentRoot /srv/www/$vhost/html/$subdomain
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
SSLEngine on SSLEngine on
SSLCertificateFile /etc/ssl/letsencrypt/$subdomain.$vhost.pem SSLCertificateFile /etc/ssl/letsencrypt/$subdomain.$vhost.pem
@ -160,7 +160,7 @@
RewriteCond %{REQUEST_URI} ^/cgi-bin/.* RewriteCond %{REQUEST_URI} ^/cgi-bin/.*
RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT] RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT]
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
@ -187,7 +187,7 @@
</IfDefine> </IfDefine>
DocumentRoot /srv/www/$vhost/html/$subdomain DocumentRoot /srv/www/$vhost/html/$subdomain
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
@ -299,7 +299,7 @@
RewriteCond %{REQUEST_URI} ^/cgi-bin/.* RewriteCond %{REQUEST_URI} ^/cgi-bin/.*
RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT] RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT]
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
</Macro> </Macro>
@ -324,7 +324,7 @@
</Location> </Location>
</IfDefine> </IfDefine>
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
@ -339,7 +339,7 @@
RewriteCond %{REQUEST_URI} ^/cgi-bin/.* RewriteCond %{REQUEST_URI} ^/cgi-bin/.*
RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT] RewriteRule ^/cgi-bin/(.*) /cgi-wrap/cgiwrap/$username/$1 [PT]
<FilesMatch ".+\.ph(ar|p|tml)$"> <FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php8.1-fpm-$username.sock|fcgi://localhost" SetHandler "proxy:unix:/run/php/phpPHPVERSION-fpm-$username.sock|fcgi://localhost"
</FilesMatch> </FilesMatch>
SSLEngine on SSLEngine on
SSLCertificateFile /etc/ssl/letsencrypt/$alias.pem SSLCertificateFile /etc/ssl/letsencrypt/$alias.pem

View File

@ -44,6 +44,9 @@ fi
# install systemd files and reload # install systemd files and reload
cp systemd/* /usr/local/lib/systemd/system/ cp systemd/* /usr/local/lib/systemd/system/
chmod 644 /usr/local/lib/systemd/system/* chmod 644 /usr/local/lib/systemd/system/*
# set php version
sed -i "s|PHPVERSION|$phpVersion|g" /usr/local/lib/systemd/system/vhost-reload-php.path
sed -i "s|PHPVERSION|$phpVersion|g" /usr/local/lib/systemd/system/vhost-reload-php.service
systemctl daemon-reload systemctl daemon-reload
# install pwgen, used to create random passwords # install pwgen, used to create random passwords
@ -97,6 +100,8 @@ chown root:root /etc/apache2/mods-available/*.conf
sed -i "s|SSLProtocol.*|SSLProtocol TLSv1.2|g" /etc/apache2/mods-available/ssl.conf sed -i "s|SSLProtocol.*|SSLProtocol TLSv1.2|g" /etc/apache2/mods-available/ssl.conf
# set vhost subodmain to domain name of server, users may want to consider changing this to a custom domain. # set vhost subodmain to domain name of server, users may want to consider changing this to a custom domain.
sed -i "s|example.com|$vhostdomain|g" /etc/apache2/mods-available/macro.conf sed -i "s|example.com|$vhostdomain|g" /etc/apache2/mods-available/macro.conf
# set php version
sed -i "s|PHPVERSION|$phpVersion|g" /etc/apache2/mods-available/macro.conf
# a2enmod proxy_fcgi rewrite headers expires ssl http2 remoteip macro # a2enmod proxy_fcgi rewrite headers expires ssl http2 remoteip macro
a2enmod cgid proxy_fcgi proxy_http rewrite headers expires ssl http2 macro a2enmod cgid proxy_fcgi proxy_http rewrite headers expires ssl http2 macro
# # sed -i "s|CustomLog|#CustomLog|g" /etc/apache2/sites-available/000-default.conf # # sed -i "s|CustomLog|#CustomLog|g" /etc/apache2/sites-available/000-default.conf

View File

@ -2,7 +2,7 @@
Description="Reload PHP-FPM on changes to pool config files" Description="Reload PHP-FPM on changes to pool config files"
[Path] [Path]
PathChanged=/etc/php/8.1/fpm/pool.d/ PathChanged=/etc/php/PHPVERSION/fpm/pool.d/
Unit=vhost-reload-php.service Unit=vhost-reload-php.service
[Install] [Install]

View File

@ -4,4 +4,4 @@ Description=Reload PHP-FPM
[Service] [Service]
Type=oneshot Type=oneshot
ExecStartPre=sleep 2 ExecStartPre=sleep 2
ExecStart=systemctl try-reload-or-restart php8.1-fpm ExecStart=systemctl try-reload-or-restart phpPHPVERSION-fpm