Using Composer to manage dependencies in Heroku PHP apps
Heroku is a very nice Platform-as-a-Service provider that allows you to focus on writing applications instead of managing servers. If your application code is already managed in Git, in most cases you only need to create a Heroku app setup, and then git push to deploy it on Heroku. Scaling your app is easy and there are many useful add-ons available in their "app store".
Until now PHP developers haven't had this convenience, but as Composer is emerging as the default PHP package manager, I've now added support for it. Before the pull request gets accepted, Composer dependency handling can already be used by specifying my custom PHP buildpack when creating Heroku apps.
I've written a simple example app to show how this works.
First you need to create the folder for your app and make it a Git repository:$ mkdir myapp $ cd myapp $ git init
Then create the Heroku app using a custom buildpack (when the pull request is accepted you can skip the buildpack definition):$ heroku create -s cedar --buildpack https://github.com/bergie/heroku-buildpack-php.git my-cool-app
For Heroku to recognize the app as a PHP one, you also need to have an index.php. In this case with the following code:
Urlizer serviceString to URLize
Now add and commit these files, and then deploy to Heroku:$ git push heroku master
You should see that Heroku notices the Composer dependencies and installs them:----- Heroku receiving push ----- Fetching custom buildpack... done ----- PHP app detected ----- Bundling Apache version 2.2.22 ----- Bundling PHP version 5.3.10 ----- Installing Composer dependencies Installing dependencies - Package phptal/phptal (dev-master) Cloning e146361f25b8672d364695b757eddf1c169e05d2 - Package midgard/midgardmvc-core (dev-master) Cloning 2b00d38cb2fea42c8f9791c5ecc7270dc81182e8 - Package midgard/midgardmvc-helper-urlize (dev-master) Cloning 92d0c8c638c389b7be1887ca67cd334f51932912 midgard/midgardmvc-core suggests installing ext-midgard2 (=10.05.5) Writing lock file Generating autoload files ----- Discovering process types Procfile declares types - (none) Default types for PHP - web ----- Compiled slug size is 13.2MB ----- Launching... done, v13
And that is it! You can see an example of this app at http://urlizer-service.herokuapp.com/.