doubi9531
2017-01-06 05:43
浏览 106

MongoDB PHP驱动程序无法在Linux AWS上运行

I'm trying to install the MongoDB PHP driver so I can connect to a MongoDB Server on another machine. Using PHP 5.6 on AWS Linux.

I used sudo pecl install mongodb. Initially there were several errors regarding dependencies but I added them all and it then seems to have installed without any errors.

However, when loading phpinfo() I don't see any reference to Mongo. When I try to run:

$connection = new MongoClient(); I get

PHP Fatal error:  Class 'MongoClient' not found in /var/www/html/mongo.php on line 3

I did put in extension=mongodb.so into my php.ini but that results in another error:

PHP Startup: Unable to load dynamic library '/usr/lib64/php/5.6/modules/mongodb.so' - /usr/lib64/php/5.6/modules/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0

It seems this error has to do with the order in which json loads relative to MongoDB. But as in my case it doesn't appear MongoDB is loading at all I'm not sure if that applies here.

I'd appreciate assistance as to why this isn't working.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试安装MongoDB PHP驱动程序,以便我可以连接到另一台机器上的MongoDB服务器。 在AWS Linux上使用PHP 5.6。

我使用了 sudo pecl install mongodb 。 最初有几个关于依赖关系的错误,但我添加了所有错误,然后它似乎安装没有任何错误。

然而,当加载 phpinfo()时我不喜欢 看不到任何关于Mongo的提法。 当我尝试运行时:

$ connection = new MongoClient(); 我得到

  PHP Fatal 错误:在第3行的/var/www/html/mongo.php中找不到类'MongoClient'
   
 
 

我确实输入了 extension = mongodb。 所以进入我的php.ini但导致另一个错误:

  PHP启动:无法加载动态库'/usr/lib64/php/5.6/modules  /mongodb.so' -  /usr/lib64/php/5.6/modules/mongodb.so:未定义的符号:php_json_serializable_ce在第0行的未知
   
 
 

这似乎是这个 错误与json相对于MongoDB加载的顺序有关。 但就像我的情况一样,MongoDB根本没有加载我不确定这是否适用于此。

我很感激为什么这不起作用的帮助。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongtanxi5676756 2017-01-06 06:04
    已采纳

    I had faced the same situation and i got this solution from mongo developers You don't need to put mongodb.so in php.ini instead make it a separate module If you are using debian

    cat << EOF > /etc/php5/mods-available/mongodb.ini
    ; priority=99
    extension=mongodb.so
    EOF
    php5enmod mongodb
    

    if you are using fedora

    echo "extension=mongodb.so" > /etc/php.d/50-mongodb.ini
    

    Then restart your apache And it will work fine.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongluan0020 2017-01-06 05:52

    Long story short, use of MongoClient for PHP is deprecated. ( https://github.com/mongodb/mongo-php-driver/issues/300#issuecomment-210820288 )

    Instead of $connection = new MongoClient(); You'll want to use $connection = new MongoDB\Driver\Manager();

    Hope this helps.

    评论
    解决 无用
    打赏 举报
  • dongmin4052 2018-05-10 16:00

    For me, after following the sage advice above, I still couldn't see mongo in phpinfo. I finally resorted to uninstalling and reinstalling mongodb using pecl and noticed at the end of the output from make, it said:

    configuration option "php_ini" is not set to php.ini location
    

    Followed this: pecl config-set php_ini /etc/php.ini

    Then:

    sudo pecl uninstall mongodb
    sudo pecl install mongodb
    systemctl restart php-fpm
    systemctl restart httpd
    

    After that, mongo showed in both php -i:

     php -i|grep mongo
    /etc/php.d/50-mongodb.ini
    mongodb
    libmongoc bundled version => 1.9.4
    libmongoc SSL => enabled
    libmongoc SSL library => OpenSSL
    libmongoc crypto => enabled
    libmongoc crypto library => libcrypto
    libmongoc crypto system profile => disabled
    libmongoc SASL => disabled
    libmongoc compression => enabled
    libmongoc compression snappy => disabled
    libmongoc compression zlib => enabled
    mongodb.debug => no value => no value
    

    And phpinfo:

    http://1.2.3.4/phpinfo.php/
    
    mongodb
    MongoDB support enabled
    MongoDB extension version   1.4.3
    MongoDB extension stability stable
    libbson bundled version 1.9.4
    libmongoc bundled version   1.9.4
    libmongoc SSL   enabled
    libmongoc SSL library   OpenSSL
    libmongoc crypto    enabled
    libmongoc crypto library    libcrypto
    libmongoc crypto system profile disabled
    libmongoc SASL  disabled
    libmongoc compression   enabled
    libmongoc compression snappy    disabled
    libmongoc compression zlib  enabled
    Directive   Local Value Master Value
    mongodb.debug   no value    no value
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题