DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > MongoDB and the New PHP on Heroku

MongoDB and the New PHP on Heroku

Chris Chang user avatar by
Chris Chang
·
May. 07, 14 · Java Zone · Interview
Like (0)
Save
Tweet
6.08K Views

Join the DZone community and get the full member experience.

Join For Free

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.


PHP MongoDB

Published at DZone with permission of Chris Chang, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Leverage Method Chaining To Add Smart Message Routing in Java
  • Instancio: Test Data Generator for Java (Part 2)
  • Creating a REST Web Service With Java and Spring (Part 1)
  • Refactoring Java Application: Object-Oriented And Functional Approaches

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo