首页 > 解决方案 > Composer 在您的平台中检测到问题:您的 Composer 依赖项需要 PHP 版本 ">= 8.0.0"。(Nginx/Ubuntu)

问题描述

向我的作曲家添加新的依赖项时,一切都在本地运行良好。但是,将其推送到 Ubuntu (20.04) 服务器时,出现以下错误。

Composer 在您的平台中检测到问题:您的 Composer 依赖项需要 PHP 版本 ">= 8.0.0"。

但是我已经将我的服务器版本的 php 也更新到了 8.0.12,或者至少当我在 Ubuntu 服务器中查找 php 的版本时,我发现

> # php -v PHP 8.0.12 (cli) (built: Oct 22 2021 12:34:48) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.12, Copyright (c) Zend
> Technologies
>     with Zend OPcache v8.0.12, Copyright (c), by Zend Technologies

深入研究,我在 Nginx 的错误日志中发现了以下语句:

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.3. in /var/www/html/vendor/composer/platform_check.php on line 24" while reading response header from upstream, client: ........, server: _, request: "GET /login HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:"

它明确引用了“php7.4-fpm.sock”,所以没有 php8。这对我来说很奇怪,因为我更改了 etc/nginx/sites-available/default 文件中的引用,如下所示:

location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        # fastcgi_index index.php;
        # fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        # fastcgi_read_timeout 300;
        # include fastcgi_params;
    }

所以不知何故它仍然引用php 7.4版。我尝试使用 sudo apt-get autoremove 删除 php7.4-fpm 文件,因为我收到一条消息说它们不再使用,但随后出现 502 bad gateway 错误,如下所示

connect() to unix:/var/run/php/php7.4-fpm.sock failed

真的很想得到一些帮助,因为我已经坚持了一段时间了。

*注意:我也尝试过的建议

composer install --ignore-platform-reqs

但这导致了 501 内部错误。

** 添加站点可用配置的完整代码:

server {
    listen 80;
    server_name _ DOMAIN www.DOMAIN;
    root /var/www/html/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    fastcgi_read_timeout 300;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        # fastcgi_index index.php;
        # fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        # fastcgi_read_timeout 300;
        # include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

FIX 在偶然发现以下教程后,我终于找到了解决方法

https://www.vultr.com/docs/upgrade-php-7-4-to-php-8-0-on-ubuntu-20-04-with-nginx

我不完全知道它做了什么,但它肯定是配置的第 4 步,因为我在其他教程中从未见过这些步骤。可能是替换了套接字,但对我来说仍然很奇怪,因为好像我没有新的套接字。

标签: phplaravelubuntunginx

解决方案


Composer 必须使用 PHP 7.4。我的建议是在这里下载一份新的作曲家:

https://getcomposer.org/download/

并像这样执行作曲家:

php composer.phar install

既然你知道php -v版本是 8.0.12


推荐阅读