php - 在 Apple M1 上运行 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].
解决方案
您的错误消息似乎是 Composer 生成的错误。composer 的文档似乎暗示任何版本 >= 5.3.2 就足够了src。然而,由于 PHP 8.1 直到6 月才进入 Alpha 版,我可以想象在一段时间内不会有官方支持。
我确实快速搜索了您的错误并得到了这篇文章,其中指出 8.1 引入的一项重大更改是传递null
给一个不可为空的函数。官方 PHP 文档strpos()
表明 3 个参数中的任何一个都不能为strpos()
空,因此在 8.1 中的内部函数不再允许在以前的版本中“允许”由于标量类型,因此您可能需要等待 Composer正式支持8.1。
即使你确实修复了 Composer,你仍然在使用 Laravel 不受支持的 PHP 版本。从他们的 gitcomposer.json
文件中指定
"php": "^7.3|^8.0",
所以 PHP 8.1 不符合规范规定的 PHP 8.0.x 的要求^8.0
。因此,当您做到这一点时,您可能会遇到不受支持的错误。
修复上述所有错误的最简单、最安全的解决方案是坚持使用 PHP 8.x,除非有充分的理由使用 PHP 8.1。
推荐阅读
- angular - 自动发布带有 versionNumber 的新代码 Angular4
- c# - Elmah Raise() 记录内部异常
- arrays - 如何在打字稿中定义数组中的数组?
- javascript - Angular 4-在表格中添加行
- antlr - 左递归删除
- react-native - 在 React 中尝试使用 setTimeout 调用函数来延迟
- windows-10 - cx_Freeze 错误模块 SSL 不可用 Python 3.7 Windows 10
- python - Python 类型错误:可视化只需要 1 个参数,给定 53
- javascript - 一旦抛出异常,try-catch 语句就中断 try-block
- postgresql-10 - 如何为我的 PostgreSQL10 安装 pgAudit?