无法使用composer在symfony2中安装mongodb doctrine

时间:2014-01-01 14:51:54

标签: php mongodb symfony composer-php

我跟随官方documentation

当我运行composer update时出现此错误: 您的要求无法解析为可安装的软件包。

  Problem 1
    - doctrine/mongodb 1.0.4 requires ext-mongo >=1.2.12,<1.6-dev -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.0.3 requires ext-mongo >=1.2.12,<1.5-dev -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.0.2 requires ext-mongo >=1.2.12,<1.4-dev -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.0.1 requires ext-mongo >=1.2.12,<1.4-dev -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.0.0 requires ext-mongo >=1.2.12,<1.4-dev -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb-odm 1.0.0-BETA9 requires doctrine/mongodb 1.0.* -> satisfiable by doctrine/mongodb[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4].
    - Installation request for doctrine/mongodb-odm 1.0.0-BETA9 -> satisfiable by doctrine/mongodb-odm[1.0.0-BETA9].

当我运行php -m时,我找不到mongo扩展,但服务器正在运行,我可以在PHP中使用Mongo,有谁知道问题应该是什么? 我怀疑这个学说找不到mongo扩展.. 谢谢 !

3 个答案:

答案 0 :(得分:19)

我修好了! 正如预期的那样,这是因为扩展所以如果您遇到与我相同的问题,请采取以下步骤:the requested PHP extension mongo is missing from your system.

  1. 运行命令:php --ini,您将看到所有配置文件都已解析!对我来说,我使用PHP-fpm,我认为所需的唯一php.ini文件是在fpm文件夹中,但我错了在CLI文件夹中有一个php.ini文件,它是这个文件夹告诉服务器哪些模块被加载,它与doctrine从中读取扩展名的文件完全相同。
  2. 打开CLI / php.ini并在最后添加此行extension=mongo.so
  3. 重启PHP:service php5-fpm restart
  4. 就是这样!

答案 1 :(得分:1)

for OSX:

brew install php56-mongo

如果错误输出:请仔细阅读错误消息并按照它重新运行命令。

源:

http://php.net/manual/en/mongo.installation.php#mongo.installation.osx

答案 2 :(得分:0)

Linux

要安装PHP的MongoDB扩展,请运行:

sudo apt-get install php-mongo

另请参阅:Easiest way to install Mongodb PHP extension in Ubuntu 13.10 (saucy)?