PHP cannot find MongoDB driver

你离开我真会死。 提交于 2019-11-29 12:30:52

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

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.

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

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