简体   繁体   English

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

I have a fresh Pop.OS 20.10 (Basically Ubuntu for those not familiar with Pop,OS).我有一个新的 Pop.OS 20.10(对于那些不熟悉 Pop,OS 的人来说,基本上是 Ubuntu)。 I've installed Apache, php 7.2.我已经安装了 Apache、php 7.2。 7.4 & 8.0. 7.4 和 8.0。 Each version is running as FPM and each service is up and running.每个版本都作为 FPM 运行,每个服务都启动并运行。 I have several vhosts setup and using FilesMatch to indicate which version of php should run on each host.我有几个虚拟主机设置并使用 FilesMatch 来指示 php 的哪个版本应该在每个主机上运行。

The problem is they all show php 8.0 when running phpinfo() no matter what the vhost config says.问题是无论虚拟主机配置如何,在运行 phpinfo() 时它们都显示 php 8.0。 Anyone have any ideas?有人有想法么?

Here's one of the host files:这是主机文件之一:

<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 service: 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

From /etc/php/7.4/fpm/pool.d/www.conf来自 /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

Let me know if you need to see anything else.如果您需要查看其他内容,请告诉我。

Update:更新:

Thanks to Alfredo who determined this simplified solution :感谢Alfredo确定了这个简化的解决方案

<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.我有同样的问题,现在意识到它是在最后一组 php 更新之后开始的。 Just ran the latest updates again and now it works again.刚刚再次运行最新的更新,现在它又可以工作了。

Okay, spoke to soon, the updates didn't fix it.好的,很快就谈过了,更新没有解决它。

Here's what did work for me this was added to the vhost config file in sites-enabled:这是对我有用的,它被添加到启用站点的虚拟主机配置文件中:

    <IfModule proxy_fcgi_module>
        # Enable http authorization headers
        <IfModule setenvif_module>
        SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
        </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>

Essentially this is the code copied from the /etc/conf-available/php7.2-fpm.conf file.本质上,这是从 /etc/conf-available/php7.2-fpm.conf 文件复制的代码。 As I'm not an expert on Apache I can't explain why it worked when the simpler statement didn't.由于我不是 Apache 方面的专家,我无法解释为什么当更简单的语句不起作用时它会起作用。 But I've edited three different vhosts and they are now getting the correct version of PHP.但是我已经编辑了三个不同的虚拟主机,他们现在得到了正确版本的 PHP。

FYI: this issue is also being discussed here: https://askubuntu.com/questions/1316859/php-fpm-working-but-ignoring-version-from-sethandler/1317014#1317014仅供参考:这里也在讨论这个问题: https://askubuntu.com/questions/1316859/php-fpm-working-but-ignoring-version-from-sethandler/1317014#1317014

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM