在 Apple M1 上运行 Laravel

时间:2021-05-20 22:15:44

标签: php laravel

我正在 Macbook Air M1 上安装 Laravel,但是遇到了问题。 PHP 版本为 PHP 8.1.0-dev,Composer 版本为 2.0.13。当我跑步时:

$ composer create-project laravel/laravel example-app

我收到此错误消息:

Deprecation Notice: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in phar:///opt/homebrew/Cellar/composer/2.0.13/bin/composer/src/Composer/DependencyResolver/SolverProblemsException.php:111

Problem 1
    - phpunit/phpunit[9.3.3, ..., 9.4.0] require phpspec/prophecy ^1.11.1 -> satisfiable by phpspec/prophecy[1.11.1, ..., 1.13.0].
    - phpspec/prophecy 1.11.x-dev is an alias of phpspec/prophecy dev-master and thus requires it to be installed too.
    - phpunit/phpunit[9.4.1, ..., 9.5.x-dev] require phpspec/prophecy ^1.12.1 -> satisfiable by phpspec/prophecy[1.12.1, 1.12.2, 1.13.0].
    - phpspec/prophecy[dev-master, 1.12.0, ..., 1.13.0] require php ^7.2 || ~8.0, <8.1 -> your php version (8.1.0-dev) does not satisfy that requirement.
    - phpspec/prophecy 1.11.1 requires php ^7.2 -> your php version (8.1.0-dev) does not satisfy that requirement.
    - Root composer.json requires phpunit/phpunit ^9.3.3 -> satisfiable by phpunit/phpunit[9.3.3, ..., 9.5.x-dev].

1 个答案:

答案 0 :(得分:2)

您的错误消息似乎是 Composer 生成的错误。 composer 的文档似乎暗示 any 版本 >= 5.3.2 就足够了 srcHowever, with PHP 8.1 not even being in Alpha until June,我想可以肯定地说,在一段时间内不会对此提供官方支持。

我确实快速搜索了您的错误并得到了 this article,它指出 8.1 引入的重大更改之一是将 null 传递给不可为空的函数。 strpos() 的官方 PHP 文档表明 strpos() 中的 3 个参数都不能为空,因此在以前的版本中由于标量类型而“允许”的内容在 8.1 中不再允许用于内部函数,因此您可能需要等待 Composer 正式支持 8.1。

即使您确实修复了 Composer,您仍然在为 Laravel 使用不受支持的 PHP 版本。从他们的 git composer.json 文件指定

 "php": "^7.3|^8.0",

因此 PHP 8.1 不符合 PHP 8.0.x 的要求,而这正是 ^8.0 规范所声明的。因此,当您做到这一点时,您可能会遇到不受支持的错误。


修复上述所有错误的最简单、最安全的解决方案是坚持使用 PHP 8.x,除非有充分的理由使用 PHP 8.1。