Ubuntu 20.10 (Pop OS) 与 Apache 和多个版本的 PHP-FPM FilesMatch 指令不工作

Ubuntu 20.10 (Pop OS) with Apache and multiple versions of PHP-FPM FilesMatch directive not working

我有新鲜的 Pop!OS 20.10(对于那些不熟悉 Pop!OS 的人来说基本上是 Ubuntu)。我已经安装了 Apache,php 7.2、7.4 和 8.0。每个版本都 运行ning 作为 FPM,每个服务都已启动并且 运行ning。我设置了多个虚拟主机,并使用 FilesMatch 指示每个主机上应该 运行 的 php 版本。

问题是当 运行ning phpinfo() 时,无论虚拟主机配置如何,它们都显示 php 8.0。有人有什么想法吗?

这是主机文件之一:

<VirtualHost zr1.local:80>
<FilesMatch \.php$> # Apache 2.4.10+ can proxy to unix socket 
    SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/" 
</FilesMatch> 
DocumentRoot "/var/www/zr1/web"
ServerName zr1.local
<Directory "/var/www/zr1/web">
    AllowOverride All
    Options +FollowSymLinks
    Order allow,deny
    Allow from all
    <IfModule mod_rewrite> 
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /app.php [QSA,L]
    </IfModule> 
</Directory>

FPM 服务:

php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-02-15 14:38:26 EST; 1h 28min ago
       Docs: man:php-fpm7.4(8)
    Process: 27667 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/>
   Main PID: 27664 (php-fpm7.4)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 38267)
     Memory: 11.5M
     CGroup: /system.slice/php7.4-fpm.service
             ├─27664 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             ├─27665 php-fpm: pool www
             └─27666 php-fpm: pool www

来自/etc/php/7.4/fpm/pool.d/www.conf

listen = /run/php/php7.4-fpm.sock
apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-02-15 14:54:05 EST; 1h 25min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 29642 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 29646 (/usr/sbin/apach)
      Tasks: 8 (limit: 38267)
     Memory: 15.3M
     CGroup: /system.slice/apache2.service
             ├─29646 /usr/sbin/apache2 -k start
             ├─29647 /usr/sbin/apache2 -k start
             ├─29648 /usr/sbin/apache2 -k start
             ├─29649 /usr/sbin/apache2 -k start
             ├─29650 /usr/sbin/apache2 -k start
             ├─29651 /usr/sbin/apache2 -k start
             ├─29652 /usr/sbin/apache2 -k start
             └─29705 /usr/sbin/apache2 -k start

如果您需要查看其他内容,请告诉我。

更新:

感谢Alfredo who determined this simplified solution:

<FilesMatch \.php$> # Apache 2.4.10+ can proxy to unix socket 
        <If "-f %{REQUEST_FILENAME}">
            SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/" 
        </If>
    </FilesMatch> 

Run updates. I had the same problem, now realized it started after the last set of php updates. Just ran the latest updates again and now it works again.

好的,很快联系上了,更新没有解决它。

这是对我有用的,它被添加到启用站点的虚拟主机配置文件中:

    <IfModule proxy_fcgi_module>
        # Enable http authorization headers
        <IfModule setenvif_module>
        SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=
        </IfModule>

        <FilesMatch ".+\.ph(ar|p|tml)$">
            <If "-f %{REQUEST_FILENAME}">
                SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/"
            </If>
        </FilesMatch>
        <FilesMatch ".+\.phps$">
            # Deny access to raw php sources by default
            # To re-enable it's recommended to enable access to the files
            # only in specific virtual host or directory
            Require all denied
        </FilesMatch>
        # Deny access to files without filename (e.g. '.php')
        <FilesMatch "^\.ph(ar|p|ps|tml)$">
            Require all denied
        </FilesMatch>
    </IfModule>

本质上,这是从 /etc/conf-available/php7.2-fpm.conf 文件中复制的代码。因为我不是 Apache 专家,所以我无法解释为什么在更简单的语句不起作用时它起作用了。但是我编辑了三个不同的虚拟主机,他们现在得到了 PHP.

的正确版本

仅供参考:这里也讨论了这个问题: https://askubuntu.com/questions/1316859/php-fpm-working-but-ignoring-version-from-sethandler/1317014#1317014