Laravel框架使用MongoDB遇到的问题解决[通俗易懂]

Laravel框架使用MongoDB遇到的问题解决[通俗易懂]之前说的,我一直是将macOS作为开发平台,直接在macOS系统配置Nginx PHP及MySQL,由于项目需求,需要使用到MongoDB,这篇就是一部在macOS系统下运行Laravel框架使用M…

之前说的,我一直是将macOS作为开发平台,直接在macOS系统配置Nginx PHP及MySQL,由于项目需求,需要使用到MongoDB,这篇就是一部在macOS系统下运行Laravel框架使用MongoDB遇到问题解决问题的流水账。

 

为了不污染正式开发的代码,我新建了一个Laravel工程,版本是5.5 LTS,MongoDB扩展使用的是laravel-mongodb,根据文档,安装该扩展的命令为:

composer require jenssegers/mongodb

代码100分

但是一执行这条命令,就出现了一大堆的错误:

代码100分zocoMac:laravel-test zoco$ composer require jenssegers/mongodb
Using version ^3.4 for jenssegers/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - jenssegers/mongodb v3.4.0 requires mongodb/mongodb ^1.0.0 -> satisfiable by mongodb/mongodb[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.4.2].
    - jenssegers/mongodb v3.4.1 requires mongodb/mongodb ^1.0.0 -> satisfiable by mongodb/mongodb[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.4.2].
    - jenssegers/mongodb v3.4.2 requires mongodb/mongodb ^1.0.0 -> satisfiable by mongodb/mongodb[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.4.2].
    - mongodb/mongodb 1.4.2 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.4.1 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.4.0 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.3.2 requires ext-mongodb ^1.4.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.3.1 requires ext-mongodb ^1.4.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.3.0 requires ext-mongodb ^1.4.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.2.0 requires ext-mongodb ^1.3.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.1.2 requires ext-mongodb ^1.2.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.1.1 requires ext-mongodb ^1.2.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.1.0 requires ext-mongodb ^1.2.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.5 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.4 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.3 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.2 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.1 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - mongodb/mongodb 1.0.0 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb is missing from your system.
    - Installation request for jenssegers/mongodb ^3.4 -> satisfiable by jenssegers/mongodb[v3.4.0, v3.4.1, v3.4.2].

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/etc/php/7.1/php.ini
    - /usr/local/etc/php/7.1/conf.d/ext-opcache.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

可以看出,这一步说的是该扩展依赖PHP的MongoDB扩展,那我们动手装上就是了。

macOS系统安装PHP的MongoDB扩展

上次说了,我目前的开发环境是直接用Homebrew安装的Nginx、PHP、MySQL等组件,之前是可以直接用brew安装相应的PHP扩展的,比如说:

brew install php71-mongodb

但是从Homebrew 1.5.0开始,这种方法被遗弃了,会提示Error: No available formula with the name “php71-mongodb”。如果系统不自带相应的扩展,就需要我们手动使用pecl安装,根据PHP官方文档,在macOS/Linux/Unix系统下,只需这一行命令即可:

代码100分sudo pecl install mongodb

当然,那只是一般情况,在国内特色网络情况下,如果直接运行很可能会因为网络原因而报错,建议挂个命令行dl再进行安装试试。如果实在是下载不下来,也可以到这里下载对应版本的源码包进行手动安装。

如果自动安装成功,最终看到会有这么一段输出:

Build process completed successfully
Installing "/usr/local/Cellar/php@7.1/7.1.22/pecl/20160303/mongodb.so"
install ok: channel://pecl.php.net/mongodb-1.5.3
Extension mongodb enabled in php.ini

既然成功了,PHP里面肯定会有对应的MongoDB模块了,命令行下使用php -m可以列出所有已安装的模块。

接下来,再次运行上面哪行composer安装命令:

zocoMac:laravel-test zoco$ composer require jenssegers/mongodb
Using version ^3.4 for jenssegers/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don"t install jenssegers/mongodb v3.4.2
    - Conclusion: don"t install jenssegers/mongodb v3.4.1
    - Conclusion: remove laravel/framework v5.5.43
    - Installation request for jenssegers/mongodb ^3.4 -> satisfiable by jenssegers/mongodb[v3.4.0, v3.4.1, v3.4.2].
    - Conclusion: don"t install laravel/framework v5.5.43
    - jenssegers/mongodb v3.4.0 requires illuminate/events ^5.6 -> satisfiable by illuminate/events[v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.25, v5.6.26, v5.6.27, v5.6.28, v5.6.29, v5.6.3, v5.6.30, v5.6.31, v5.6.32, v5.6.33, v5.6.34, v5.6.35, v5.6.36, v5.6.37, v5.6.38, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9, v5.7.0, v5.7.1, v5.7.2, v5.7.3, v5.7.4, v5.7.5].
    - don"t install illuminate/events v5.6.0|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.1|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.10|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.11|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.12|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.13|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.14|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.15|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.16|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.17|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.19|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.2|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.20|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.21|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.22|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.23|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.24|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.25|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.26|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.27|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.28|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.29|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.3|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.30|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.31|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.32|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.33|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.34|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.35|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.36|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.37|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.38|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.4|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.5|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.6|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.7|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.8|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.6.9|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.7.0|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.7.1|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.7.2|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.7.3|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.7.4|don"t install laravel/framework v5.5.43
    - don"t install illuminate/events v5.7.5|don"t install laravel/framework v5.5.43
    - Installation request for laravel/framework (locked at v5.5.43, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.43].

放狗搜了一把也没找到问题出在哪里,但是无意中发现了一个解决办法,就是安装指定版本的jenssegers/mongodb,由于我的Laravel版本为5.5.x,最好的就是安装3.3.x版本的jenssegers/mongodb,命令如下:

composer require jenssegers/mongodb=3.3.*

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing mongodb/mongodb (1.4.2): Downloading (100%)
  - Installing jenssegers/mongodb (v3.3.1): Downloading (100%)
jenssegers/mongodb suggests installing jenssegers/mongodb-session (Add MongoDB session support to Laravel-MongoDB)
jenssegers/mongodb suggests installing jenssegers/mongodb-sentry (Add Sentry support to Laravel-MongoDB)
Writing lock file
Generating optimized autoload files
> IlluminateFoundationComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: jenssegers/mongodb
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Package manifest generated successfully.

这下终于成功安装了jenssegers/mongodb。

后来查看jenssegers/mongodb文档的时候才发现,在jenssegers/mongodb文档安装命令下面就列出了相应的Laravel兼容版本,只是自己太大意没有仔细看文档:

Laravel version Compatibility

Laravel Package
4.2.x 2.0.x
5.0.x 2.1.x
5.1.x 2.2.x or 3.0.x
5.2.x 2.3.x or 3.0.x
5.3.x 3.1.x or 3.2.x
5.4.x 3.2.x
5.5.x 3.3.x
5.6.x 3.4.x

根据这个表格,哪个版本的Laravel安装哪个版本的jenssegers/mongodb开发者都有明确的说明,如果你的Laravel版本和我的不一致,可能需要在上述安装命令后面更改成对应的版本号。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/10687.html

(0)
上一篇 2022-12-23
下一篇 2022-12-23

相关推荐

  • mysql读写慢_docker清除缓存

    mysql读写慢_docker清除缓存Buffer pool 我们都知道我们读取页面是需要将其从磁盘中读到内存中,然后等待CPU对数据进行处理。我们直到从磁盘中读取数据到内存的过程是十分慢的,所以我们读取的页面需要将其缓存起来,所以MyS

    2023-05-19
    143
  • MySQL家族”新”成员——MySQL Shell[通俗易懂]

    MySQL家族”新”成员——MySQL Shell[通俗易懂]本文转载自“MySQL解决方案工程师”公众号,由徐轶韬翻译 标题虽然叫做MySQL家族新成员,但如果从发布时间上来看,MySQL Shell已经不能算做新成员了,它的正式版与MySQL8.0同一天诞…

    2023-01-27
    149
  • Python循环结束技巧总结!

    Python循环结束技巧总结!Python中常见的循环结构有for循环、while循环以及do-while循环。

    2024-07-05
    53
  • 免费网络爬虫软件推荐

    免费网络爬虫软件推荐网络爬虫是一种自动化程序,用于自动抓取互联网上的信息。这些信息可以是网页、图片、视频、文本等各种形式的数据。网络爬虫是非常有用的工具,可以大大减少人工获取信息的时间和工作量。

    2024-09-08
    23
  • JuiceFS v0.17 发布,通过 1270 项 LTP 测试!

    JuiceFS v0.17 发布,通过 1270 项 LTP 测试!小伙伴们大家好,JuiceFS v0.17 在国庆小长假来临之际如期发布了!这是我们在 2021 年秋季推出的第二个版本,让我们直奔主题,看看都有哪些新变化吧。 本次更新累计 80+ 提交,共有 9

    2023-04-23
    150
  • mysql源码安装_mysql 性能优化

    mysql源码安装_mysql 性能优化今天测试Linux 各个软件源 ,发现mysql 配置官方源之后,yum install -y mysql 安装了 mysql lastst 最新版, 安装完之后,奇葩的是没有提示输入密码, 所以 m

    2023-01-23
    148
  • Python是什么意思?

    Python是什么意思?Python是一种高级、解释型、功能强大的编程语言。它的诞生可以追溯到20世纪80年代末期荷兰计算机科学家Guido van Rossum创造了一种新的编程语言。他在设计Python时,主要考虑了其易读性和简洁性,因此,Python使用冒号和缩进来标记代码块,这使得Python语言具有良好的可读性和可维护性。

    2024-09-05
    21
  • 【2019年8月】OCP 071认证考试最新版本的考试原题-第19题[通俗易懂]

    【2019年8月】OCP 071认证考试最新版本的考试原题-第19题[通俗易懂]Choose two The INVOICE table has a QTY_SOLD column of data type NUMBER and an INVOTCE_DATE column o…

    2022-12-15
    151

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注