简体   繁体   English

CentOS - 在PHP中找不到Mongo类

[英]CentOS - Mongo class not found in PHP

I need the MongoDB PHP driver on my CentOS 5.4 machine. 我在CentOS 5.4机器上需要MongoDB PHP驱动程序。 My PHP version is 5.1.6. 我的PHP版本是5.1.6。 I downloaded the RPM and installed it. 我下载了RPM并安装了它。 That created several files in /usr/bin directory. 这在/ usr / bin目录中创建了几个文件。 I copied 我复制了

/usr/bin/mongo

to

/usr/lib/php/modules

which was what extension_dir showed on doing phpinfo();. 这是extension_dir在做phpinfo()时显示的内容。

I also added 我还补充道

extension=mongo.so

in /etc/php.ini. 在/etc/php.ini中。 However on executing my PHP script, i still get 但是在执行我的PHP脚本时,我仍然可以

Mongo class not found.

What's going wrong here ? 这里出了什么问题?

Also, my phpinfo() shows PHP version 5.1.6 whereas running PHP from command line shows 5.3.3. 另外,我的phpinfo()显示PHP版本5.1.6,而从命令行运行PHP显示5.3.3。 Could anything be wrong with that ? 这有什么不对吗?

Thanks in advance. 提前致谢。

You're saying your webserver and command line PHP report different versions. 您说您的Web服务器和命令行PHP报告了不同的版本。 These are going to be installed in different locations, and their extensions are API incompatible with each other. 这些将安装在不同的位置,并且它们的扩展是API彼此不兼容。

When you installed the php_mongo extension, it may have used the command line php to determine the directory to install the extension to. 当您安装php_mongo扩展时,它可能已使用命令行php来确定要安装扩展的目录。

Make sure you have the correct php_mongo for the php version of your webserver, and it is in the correct extensions directory. 确保您的网络服务器的php版本具有正确的php_mongo,并且它位于正确的扩展目录中。 (get the directory from the php.ini returned by phpinfo() ) (从phpinfo()返回的php.ini中获取目录)

I hope you realise PHP 5.1 is also many years out of date. 我希望你意识到PHP 5.1也已经过时了很多年。 Unless you have a specific reason to use a version that old, you should also look at upgrading to a more recent version. 除非您有特定原因要使用旧版本,否则您还应该考虑升级到更新版本。

Edit: 编辑:

Just read your comment "I must also mention that /usr/bin/mongo is a binary executable file but its not having a .so extension. Im copying it as is to /usr/lib/php/modules" 只需阅读你的评论“我还必须提到/ usr / bin / mongo是一个二进制可执行文件,但它没有.so扩展名。我将其复制到/ usr / lib / php / modules”

No no no! 不不不! :) :)

This is the mongo command line client. 这是mongo命令行客户端。 This is not the PHP extension! 这不是PHP扩展!

You can run a find /* -name "mongo.so" to see where the installer put the file, this will probably also give you an indication of which version of PHP it was installed for. 您可以运行find /* -name "mongo.so"来查看安装程序放置文件的位置,这可能还会告诉您安装了哪个版本的PHP。

It looks as though you are confusing the RPM-packages for the MongoDB server with the requirements to install the MongoDB PHP driver . 看起来好像你把MongoDB服务器的RPM包与安装MongoDB PHP驱动程序的要求混淆了。 The PHP driver provides access to the server from your PHP applications, and does not install any command line tools. PHP驱动程序提供从PHP应用程序访问服务器的权限,并且不安装任何命令行工具。

重启httpd!

yum service httpd restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM