Quick Tip: Deploy PHP to Heroku in Seconds

We've raved about the brilliance of Heroku before, mostly around the fact that it makes launching a Rails or Node app rather simple without having to configure your own server. But what if you want the same kind of freedom and speed of deployment with PHP? Fortunately, Heroku has quietly offered support for PHP for quite some time.

Make Sure You Have the Heroku Toolbelt

For Heroku deployment, you need the provided command line toolbelt. Follow the instructions on the same page; they'll walk you through setting up the Heroku command line toolbelt with your Heroku account.

Ready, Set, Deploy

First, create an index.php file within your application's directory, and type the following code:

This code uses pg_connect to connect to your automatically created Heroku Postgres database. We don't have the connection information yet; we'll have to wait until after we create our Heroku repository. Let's do that now. From your project directory, run the following commands:

> git init
> git add .
> heroku create
...

This automatically creates your project and adds the repository as the "heroku" branch. Now run the following commands to deploy the project: