Use Custom PHP Extensions on Heroku

Image representing Heroku as depicted in Crunc...

Did you know you can use custom PHP extensions on Heroku? Neither did I, cos I can’t find it in the documentation. But you can:

https://gist.github.com/1288447

I came across this while searching for a way or workaround to use the MongoDB PECL extension on Heroku (don’t get me started on that…).

If you can’t be bothered checking the link, the summary is this:

  1. Create a folder in your app called ‘ext’ or similar.
  2. Copy your extension into this folder.
  3. Create a php.ini file with the following contents:
    extension_dir = "/app/www/ext/"
    extension=mongo.so
    
  4. Deploy

The Five Megabyte Web Developer | Benjamin Atkin

The Five Megabyte Web Developer | Benjamin Atkin.

An interesting perspective on Heroku. As regular readers will have guessed, I recently started using Heroku for small experiments. So far I love it for being a low-friction way to try out something, and how I have the potential to quickly, easily, and relative cheaply scale any of these experiments which become popular. The article above did point out some limitations which I wasn’t clear on before, and which I’ll bear in mind. I wrote something similar in a comment to this blog post, this morning, but at the time of writing my comment is still awaiting moderation.

Like the author above, I looked into getting a VPS to have a “place of my own” to house such little projects, but ultimately decided against it. While it may offer you more control over configuration, resources, and fixed costs, ultimately you’re paying (or have paid) for the server even when you’re not using it. If you have several projects which all get regular traffic, then yes, it’s probably worth getting a VPS. But if you’re just testing the waters with a small idea every once in a while then I think it’s best to take advantage of platoforms like Heroku, App Harbor, PHP Fog, etc.