PHP cannot find MongoDB driver

前端 未结 3 835
萌比男神i
萌比男神i 2020-12-20 06:12

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

3条回答
  •  被撕碎了的回忆
    2020-12-20 07:07

    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:

     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
    

提交回复
热议问题