Hướng dẫn composer detecting wrong php version - nhà soạn nhạc phát hiện phiên bản php sai

Gần đây tôi đã gặp phải vấn đề tương tự.

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
5 đã trả lại
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
6, nhưng nhà soạn nhạc cho biết họ đang sử dụng Php 8.0,18.

Hóa ra nhà soạn nhạc đang sử dụng phiên bản PHP của riêng mình. Tập lệnh

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
7 chứa một đường dẫn được mã hóa cứng đến PHP 8. [Đối với tôi, đây là một lỗi của nhà soạn nhạc, vì nhà soạn nhạc nên tôn trọng giá trị của thuộc tính
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
8 của tệp
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
9.]

  1. Một tùy chọn có thể là bí danh

    cat /usr/bin/composer \
        | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
        > /usr/bin/composer.tmp
    mv /usr/bin/composer.tmp /usr/bin/composer
    
    7:

    alias composer='/usr/local/bin/php /usr/bin/composer.phar
    
  2. Một tùy chọn khác có thể là viết lại

    cat /usr/bin/composer \
        | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
        > /usr/bin/composer.tmp
    mv /usr/bin/composer.tmp /usr/bin/composer
    
    7:

    cat /usr/bin/composer \
        | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
        > /usr/bin/composer.tmp
    mv /usr/bin/composer.tmp /usr/bin/composer
    

Đây là cách tôi tìm ra. Đầu tiên, tôi muốn tìm vị trí của

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
7. Bằng cách sử dụng
composer: /usr/bin/composer
3, người ta có thể tìm thấy đường dẫn của lệnh
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
7. Đối với tôi, nó trở lại

composer: /usr/bin/composer

Sau đó, tôi muốn xem nội dung của

composer: /usr/bin/composer
5, vì vậy tôi có thể tìm ra lệnh
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
7 đang làm gì dưới mui xe. Bằng cách sử dụng
composer: /usr/bin/composer
7, nội dung của tập lệnh
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
7 được in. Đối với tôi, nó trở lại

#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"

Nó ở đó. Lệnh

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
7 sử dụng mã hóa hardcoded
#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
0 để thực thi tệp
#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
1.

Gần đây tôi đã làm việc trong một dự án Laravel 7. Tôi có một số dự án Laravel 7 khác đang chạy tại bản lưu trữ được chia sẻ. Đôi khi rất khó để giữ các phiên bản Laravel khác nhau trong việc lưu trữ được chia sẻ. Nó đã hiển thị các lỗi

#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
2

KIỂM TRA NỀN TẢNG:

Nhà soạn nhạc V2 đã giới thiệu nền tảng kiểm tra tính năng mới kiểm tra phiên bản PHP trước khi tự động tải khởi tạo. Nếu đặt tùy chọn này thành FALSE, nó sẽ không tạo ra đường dẫn dự án/nhà cung cấp/nhà soạn nhạc/platform_check.php trong autoloader bootstrap. Nó tải trong bootstrap và chấm dứt ứng dụng nếu phiên bản PHP không khớp.

Một nền tảng bình thường_check.php trông giống như

// platform_check.php @generated by Composer

$issues = array[];

if [![PHP_VERSION_ID ------>= 70400 && PHP_VERSION_ID < 90000]] {
    $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0" and "< 9.0.0". You are running ' . PHP_VERSION  .  '.';
}

$missingExtensions = array[];
extension_loaded['pdo'] || $missingExtensions[] = 'pdo';

if [$missingExtensions] {
    $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode[', ', $missingExtensions];
}

if [$issues] {
    echo 'Composer detected issues in your platform:' . "\n\n" . implode["\n", $issues];
    exit[104];
}

Solutions:

composer.json:

Thêm tùy chọn kiểm tra nền tảng trong phần Cấu hình Composer.json

"platform-check": false

Nó sẽ được hiển thị trong cấu hình

"config": {
     "preferred-install": "dist",
     "sort-packages": true,
     "optimize-autoloader": true,
     "platform-check": false
 },

Sau đó, bạn cần chạy

 composer update 

Sau khi cập nhật nhà soạn nhạc, sẽ có một tệp

________số 8

sẽ bị xóa.

project-path/vendor/composer

Command-line:

Bạn cũng có thể kiểm tra nền tảng đúng/sai trong dòng lệnh

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
0

Bây giờ nó sẽ không hiển thị cho bạn bất kỳ lỗi nào cho phiên bản PHP.

Mã hóa hạnh phúc!

Đọc tài nguyên:

//php.watch/articles/composer-platform-check

//getcomposer.org/doc/06-config.md#platform-check

Xin chào! Tôi vừa thử nghiệm các tùy chọn

#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
3 trong
cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
9 và nhận thấy rằng khi chạy, ví dụ: Phpunit theo cách này, tôi gặp phải một phiên bản PHP không phù hợp:
#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
1 được gọi với một EXECUTAB PHP cụ thể, thường là từ bên trong phpstorm nhưng thực thi tập lệnh với PHP được tìm thấy trong
#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
6. Sau khi đào một chút, tôi nghĩ thủ phạm là ____37 của Symfony [được gọi quanh đây trong ____38], dường như đoán chỉ PHP từ các biến môi trường, bỏ qua
#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
9 [có sẵn kể từ PHP 5.4].

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
9 của tôi:

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
1

Đầu ra của

// platform_check.php @generated by Composer

$issues = array[];

if [![PHP_VERSION_ID ------>= 70400 && PHP_VERSION_ID < 90000]] {
    $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0" and "< 9.0.0". You are running ' . PHP_VERSION  .  '.';
}

$missingExtensions = array[];
extension_loaded['pdo'] || $missingExtensions[] = 'pdo';

if [$missingExtensions] {
    $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode[', ', $missingExtensions];
}

if [$issues] {
    echo 'Composer detected issues in your platform:' . "\n\n" . implode["\n", $issues];
    exit[104];
}
1:

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
2

Khi tôi chạy lệnh này:

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
3

Tôi nhận được đầu ra sau:

cat /usr/bin/composer \
    | sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
    > /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
4

Và tôi mong đợi điều này sẽ xảy ra:

Tôi hy vọng tập lệnh được thực thi bởi

// platform_check.php @generated by Composer

$issues = array[];

if [![PHP_VERSION_ID ------>= 70400 && PHP_VERSION_ID < 90000]] {
    $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0" and "< 9.0.0". You are running ' . PHP_VERSION  .  '.';
}

$missingExtensions = array[];
extension_loaded['pdo'] || $missingExtensions[] = 'pdo';

if [$missingExtensions] {
    $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode[', ', $missingExtensions];
}

if [$issues] {
    echo 'Composer detected issues in your platform:' . "\n\n" . implode["\n", $issues];
    exit[104];
}
2 sẽ sử dụng cùng một thực thi PHP được sử dụng để gọi trình soạn thảo [8.0.0 thay vì 7.4.3 từ
#!/bin/sh

/usr/bin/php8 /usr/bin/composer.phar "$@"
6 trong trường hợp này].

Cập nhật: Tôi đã thêm

// platform_check.php @generated by Composer

$issues = array[];

if [![PHP_VERSION_ID ------>= 70400 && PHP_VERSION_ID < 90000]] {
    $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0" and "< 9.0.0". You are running ' . PHP_VERSION  .  '.';
}

$missingExtensions = array[];
extension_loaded['pdo'] || $missingExtensions[] = 'pdo';

if [$missingExtensions] {
    $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode[', ', $missingExtensions];
}

if [$issues] {
    echo 'Composer detected issues in your platform:' . "\n\n" . implode["\n", $issues];
    exit[104];
}
4 vào dòng tập lệnh, dường như đã giải quyết được. Tuy nhiên tôi cảm thấy như điều này là một chút không trực quan.: i added the
// platform_check.php @generated by Composer

$issues = array[];

if [![PHP_VERSION_ID ------>= 70400 && PHP_VERSION_ID < 90000]] {
    $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0" and "< 9.0.0". You are running ' . PHP_VERSION  .  '.';
}

$missingExtensions = array[];
extension_loaded['pdo'] || $missingExtensions[] = 'pdo';

if [$missingExtensions] {
    $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode[', ', $missingExtensions];
}

if [$issues] {
    echo 'Composer detected issues in your platform:' . "\n\n" . implode["\n", $issues];
    exit[104];
}
4 to the script line, which seems to have it resolved. However i feel like this is a bit unintuitive.

Làm cách nào để buộc nhà soạn nhạc sử dụng một phiên bản cụ thể của PHP?

Buộc nhà soạn nhạc sử dụng một phiên bản PHP cụ thể..
Sử dụng lệnh loại để tìm đường dẫn đến PHP: type -a PHP7 ..
Sau đó, tìm Composer.phar bằng lệnh Find: Find/-type f -Name "Composer.Phar" 2>/dev/null ..
Sử dụng lệnh CD để thay đổi thư mục Project/Dev/Prod. ....
Cuối cùng, hãy nói với nhà soạn nhạc sử dụng phiên bản PHP cụ thể:.

Phiên bản PHP nào được sử dụng bởi nhà soạn nhạc?

Trong trường hợp của tôi, cả hai đều sử dụng tập lệnh PHP mặc định của tôi [đó là phiên bản 7.4]. Vì vậy, trong khi phiên bản 7.2 được sử dụng để chạy trình soạn thảo, các tập lệnh được gọi bởi nhà soạn nhạc sử dụng lệnh mặc định. Trên thực tế, tùy chọn nền tảng quan trọng là giải quyết các yêu cầu, vì vậy bạn nên thêm nó [trong nhà soạn nhạc dự án của bạn. JSON].version 7.4]. So, while the 7.2 version is used to run Composer, the scripts called by Composer use the default command. Actually, what the platform option is important for is resolving the requirements, so you should add it [in your project composer. json].

Làm cách nào để cập nhật phiên bản trình soạn thảo của tôi lên một phiên bản cụ thể?

Để thay đổi thành phiên bản, một lần chạy lệnh tự cập nhật và vượt qua cờ11.Điều này sẽ thay đổi trình soạn thảo thành phiên bản một và bây giờ bạn có thể cài đặt các phụ thuộc của mình.Khi bạn đã cài đặt các phụ thuộc của mình, bây giờ bạn có thể chạy cùng một lệnh và chuyển vào trong số 2 như cờ và điều này sẽ chuyển trở lại nhà soạn nhạc phiên bản 2.run the self-update command and pass in the –1 flag. This will change composer to version one and now you can install your dependencies. Once you have installed your dependencies, now you can run the same command and pass in –2 as the flag and this will switch back to composer version 2.

Nhà soạn nhạc có thể cập nhật PHP không?

Nếu dự án của bạn đang chạy Php 7.4, bạn muốn đảm bảo rằng tất cả các phụ thuộc khác của bạn hoạt động với PHP 7.4.Sau đó, bạn chỉ có thể chạy Cập nhật nhà soạn nhạc php-với tất cả các phụ thuộc giống như bạn sẽ làm bất cứ điều gì khác.Lưu ý: Nếu bạn đang nhận được lỗi trên về compser.you can just run composer update php --with-all-dependencies just like you would anything else. Note: if you are receiving the error above about the compser.

Bài Viết Liên Quan

Chủ Đề