我想在同一个 Debian/Apache 服务器上使用 FastCGI 的多个 PHP-FPM 版本。使用:
- Debian v9.12,
- Apache v2.4.25,
- php5.6-fpm,
- php7.4-fpm,
- libapache2-mod-fcgid v1:2.3.9-1+b1,
- libapache2-mod-php5.6 v5.6.40-26+0~20200320.32+debian9~1.gbpec51cd,
- libapache2-mod-php7.4 v7.4.14-1+0~20210112.34+debian9~1.gbpaa175a。
我想在同一台服务器上使用 php5.6-fpm、php7.4-fpm。
该网站应默认使用 PHP v5.6,并应在 php74.mysite.com 子域上使用 PHP v7.4。
我使用以下 Apache 配置文件:
我的站点.conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot "/var/www/mysite.com/htdocs"
ServerName mysite.com:443
ServerAlias *.mysite.com:443 www.mysite.com:443
SecAuditEngine On
RewriteEngine On
SSLEngine on
LogLevel warn
ServerSignature Off
<FilesMatch "\.php(/.*)$">
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/var/www/mysite.com/htdocs"
</FilesMatch>
<Proxy fcgi://localhost/var/www/mysite.com/htdocs enablereuse=on max=10>
ProxySet connectiontimeout=3600 timeout=3600
</Proxy>
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule (.*) - [H=text/html]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mysite.com/htdocs>
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride None
Require all granted
</Directory>
ErrorLog /var/www/mysite.com/log/error.log
CustomLog /var/www/mysite.com/log/access.log combined
CustomLog /var/www/mysite.com/log/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
php74.mysite.conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot "/var/www/php74.mysite.com/htdocs"
ServerName php74.mysite.com
SSLEngine on
SecAuditEngine On
RewriteEngine On
SSLProxyEngine on
LogLevel debug
LogLevel alert rewrite:trace8
ProxyPreserveHost On
<Directory /var/www/php74.mysite.com/htdocs>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch "\.php(/.*)$">
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/var/www/php74.mysite.com/htdocs"
</FilesMatch>
<Proxy "fcgi://localhost/var/www/php74.mysite.com/htdocs" enablereuse=on max=10>
</Proxy>
<Directory /var/www/php74.mysite.com/htdocs>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
DirectoryIndex index.php
</Directory>
ErrorLog /var/www/php74.mysite.com/log/error.log
CustomLog /var/www/php74.mysite.com/log/access.log combined
CustomLog /var/www/php74.mysite.com/log/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
已将 phpinfo.php 上传至两个站点的 htdocs:
<?php
phpinfo();
?>
不幸的是在 php74.mysite.com 上显示:
PHP Version 5.6.40-26+0~20200320.32+debian9~1.gbpec51cd
...
Configuration File (php.ini) Path /etc/php/5.6/fpm
Loaded Configuration File /etc/php/5.6/fpm/php.ini
如何强制在 php74.mysite.com 上使用 PHP v7.4?
答案1
该域名与第二个站点和第一个站点php74.mysite.com
都匹配。ServerName php74.mysite.com
ServerAlias *.mysite.com
强制php74.mysite.conf
文件首先由 Apache 解析(例如重命名为_php74.mysite.conf
)。