-
Install any of the Mongo add-ons available at http://addons.heroku.com
-
Vendor the Mongo driver with your application. You can download it here:
https://github.com/wuputah/heroku-libraries/raw/master/php/mongo/mongo.so
Add it to a folder like "ext".
-
Add a php.ini file to the root of your application:
extension_dir = "/app/www/ext/" extension=mongo.so
-
Use it! Parse the db name out of the env var (keep in mind different Mongo providers will give you different urls, like MONGOHQ_URL or MONGOLAB_URL).
Here's a sample index.php:
<?php # get the mongo db name out of the env $mongo_url = parse_url(getenv("MONGO_URL")); $dbname = str_replace("/", "", $mongo_url["path"]); # connect $m = new Mongo(getenv("MONGO_URL")); $db = $m->$dbname; $col = $db->access; # insert a document $visit = array( "ip" => $_SERVER["HTTP_X_FORWARDED_FOR"] ); $col->insert($visit); # print all existing documents $data = $col->find(); foreach($data as $visit) { echo "<li>" . $visit["ip"] . "</li>"; } # disconnect $m->close(); ?>
Created
October 14, 2011 21:44
-
-
Save pedro/1288447 to your computer and use it in GitHub Desktop.
--Issue resolved by adding compose.json in root directory with following code
{
"require": {
"ext-mongo": "*"
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have tried follwoing steps and ##GETTING ERROR -
Fatal error: Class 'Mongo' not found in /app/mongo.php on line 13
Installed MongoHQ add-on in heroku app.
Downloaded - https://github.com/wuputah/heroku-libraries/raw/master/php/mongo/mongo.so driver and then created "ext" folder in root directory and saved mongo.so in that dir.
Added php.ini file in my root directory with following code
Uploaded following code on server named mongo.php file
GETTING ERROR -
Fatal error: Class 'Mongo' not found in /app/mongo.php on line 13