PHP cannot find MongoDB driver

為{幸葍}努か 提交于 2019-12-18 07:22:05

问题


On my Ubuntu 12.04 installation I install PHP5 (5.5) from the ondej package. Everything works ok with the PHP, Apache and MySQL, I also successfully install Mongo daemom and Mongo client. But then PHP cannot locate the MongoDB driver in pear.

I have followed all the steps explained in the documentation I have added the extension to the php.ini file in the CLI folder restarted the server updated everything and restart the server again.

I have been stuck on this issue quite long time now. Where should I look in. My Ubuntu is also running on a virtual machine I have tried both on VMWare and VirtualBox (not that this has anything to do as far as I know).

Thanks

P.S. There are two similar issues here but they did not help me to solve my problem.


回答1:


I can give you my build recipe from a fresh 12.04 installation. Fresh being simply running through the configuration and only selecting the "SSH server" option at the end for convenience.

MongoDB installation is optional, so if you want this on a different server then skip. But the general instructions come from:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

All commands split up and not automated so you can see the steps:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get install software-properties-common
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
sudo apt-get install mongodb-10gen
sudo apt-get install build-essential
sudo apt-get install php5-dev
sudo apt-get install libcurl4-openssl-dev
sudo pecl install mongo

Lots of compiler output. Ending with success and asking to mofidy php.ini

Edit the CLI settings. And do the same for the apache config as well

sudo vi /etc/php5/cli/php.ini
sudo vi /etc/php5/apache2/php.ini

Personal preference, after the comments on 'Dynamic Extensions'

extension=mongo.so

Test that usage and connection does not throw an error. Create test.php:

<?php

    $m = new MongoClient('mongodb://localhost/',
        array('connectTimeoutMS'=> 500, 'socketTimeoutMS' => 500 ));

?>

And run from command line:

php test.php

No errors. Then you are all set up.

$ php -v
PHP 5.5.3-1ubuntu2.1 (cli) (built: Dec 12 2013 04:24:35)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies



回答2:


Just in case here are my steps for php and mongo installation which I use on amazon:

sudo -i
add-apt-repository ppa:ondrej/php5
apt-get update && apt-get upgrade && apt-get install php5

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
apt-get update && apt-get install mongodb-10gen

apt-get install php-pear php5-dev
pecl install mongo

nano /etc/php5/apache2/php.ini

and change

error_reporting = E_ALL
display_errors = On

and add: extension=mongo.so

service apache2 restart

This will install you latest PHP, mongo, and latest mongodriver.




回答3:


Install MongoDB PHP Driver:

sudo apt-get install php5-dev php5-cli php-pear
sudo pecl install mongo

Install php5-mongo Pacakge:

sudo apt-get install php5-mongo

Open your php.ini file and add to it:

extension=mongo.so



来源:https://stackoverflow.com/questions/22392530/php-cannot-find-mongodb-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!