Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MongoDB and the New PHP on Heroku

DZone's Guide to

MongoDB and the New PHP on Heroku

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Update 5/5/14 10:45PM: Heroku’s default PHP buildpack now allows Composer to install the MongoDB extension. You do not need to use the develop branch. To enable, add “ext-mongo” to the composer.json file as described in the Solution section.

One of our close Platform-as-a-Service (PaaS) partners, Heroku, recently announced its official public beta for new PHP features. This announcement was met with much excitement from the developer community, and the MongoLab team looks forward to working with PHP developers on Heroku who want to power their apps with fully-managed MongoDB databases.

This post will cover how to install the PHP MongoDB extension on Heroku.

Running PHP on Heroku

If you’re just getting started with PHP on Heroku, we highly recommend visiting their Dev Center for a quick tutorial. Heroku leverages a PHP buildpack to help you quickly get up and running with a standard PHP environment and come bundled with the Composer package for easy package management.

Current challenge with Heroku’s PHP buildpack

While Heroku’s buildpack and the Composer package help you get started quickly, they have some limitations in regards to MongoDB. PHP deployments come packaged with built-in extensions such as cURL and MySQL, along with a few other extensions that can be enabled in the composer.json file. Currently however, MongoDB cannot be enabled through Composer.

We recently worked with one of our users having trouble getting the MongoDB extension installed. Because of Heroku’s ephemeral filesystem, conventional methods such as changing the php.ini file and using ‘pecl install mongo’ did not work. While Heroku does allow for custom INI settings via per-directory .user.ini files, that does not allow you to load extensions.

Solution

Thanks to David at Heroku Support, we have a solution! To ensure that your PHP deployments install the MongoDB extension every time, you can change your Heroku configuration to use the develop branch of the Heroku buildpack. Using the develop branch allows you to install the MongoDB extension via Composer. Run the command

 
heroku config:set BUILDPACK_URL= https://github.com/heroku/heroku-buildpack-php#develop

…then enable the extension in your composer.json by adding:

{
  “require”: {
    “ext-mongo”: ”*”
  }
}

Commit and push this change then you’re good to go!

Happy hacking!

We hope this post helps you get up and running on Heroku with PHP and MongoDB. The Heroku team expects the develop branch to be pushed to master soon, and you can track the changes on either the Heroku changelog or on their twitter handle @HerokuChangelog.


Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}