user1013550
user1013550

Reputation: 53

PHP & Mongo broken after Mac OSX Mavericks upgrade

Following an OSX 10.9.3 upgrade a number of things didn't work. Apache, Mongo and PHP are all working independently now, however the mongo extension for php is not. I am hoping the stackoverflow community can help. Here's the basic problem:

$ sudo pecl install mongo
pecl/mongo is already installed and is the same as the released version 1.5.3
install failed

$ php --re mongo
Exception: Extension mongo does not exist

Pecl and PHP are having a disagreement on whether the mongo extension is there. mongo.so does physically exist here: /opt/local/lib/php/extensions/no-debug-non-zts-20090626/mongo.so where it was installed and here: /usr/lib/php/extensions/no-debug-non-zts-20100525 where I copied it because that is where php.ini points. It is executable in both places. It seems odd that it is getting installed in the wrong spot, so maybe there is a pecl config that needs to be flipped? Also pecl is not finding php.ini at the end of the install, but I am updating manually.

The best summary of the directions for getting back up after the 10.9 upgrade appears to be here: http://fighterpilotstress.blogspot.com/2013/10/installing-mongodb-driver-with-php-on.html and I have followed it faithfully. I have also installed the commandline tools as referenced here: Unable to install mongodb php driver on mac os 10.9.

Relavent php.ini lines:

include_path = ".:/usr/lib/php/pear"    
extension=mongo.so

any help appreciated. Thanks, Brian

Upvotes: 3

Views: 554

Answers (1)

Faisal
Faisal

Reputation: 772

I hanged up for a while in the same situation on ubuntu, then I just tried

1) In your phpinfo() screen, make sure the Configuration file Path and Loaded Configuration File match the PHP file you are editing. If not, then find the correct php.ini and add the mongo.so extension.

2) In your phpinfo() screen, look at the extension_dir value and confirm that mongo.so exists in that directory. If not, find the mongo.so file and copy it to this directory.

3) Restart your web server.

4) If it's still not working, take a look at the web server & php logs for clues as to why the extension might not be loading.

from Error enabling MongoDB module

All was ok on my side, but still I kept getting, $ php --re mongo Exception: Extension mongo does not exist

then I checked with this test script and was able to connect to mongoDB.

<?php
try {
    // open connection to MongoDB server
    $conn = new Mongo('localhost');

    // access database
    $db = $conn->test;

    // access collection
    $collection = $db->items;

    // execute query
    // retrieve all documents
    $cursor = $collection->find();

    // iterate through the result set
    // print each document
    echo $cursor->count() . ' document(s) found. <br/>';
    foreach ($cursor as $obj) {
        echo 'Name: ' . $obj['name'] . '<br/>';
        echo 'Quantity: ' . $obj['quantity'] . '<br/>';
        echo 'Price: ' . $obj['price'] . '<br/>';
        echo '<br/>';
    }

    // disconnect from server
    $conn->close();
} catch (MongoConnectionException $e) {
    die('Error connecting to MongoDB server');
} catch (MongoException $e) {
    die('Error: ' . $e->getMessage());
}
?> 

Therefore try the script and if you are able to connect without errors, forget about the extension :).

Upvotes: 1

Related Questions