Hosting PHP with Heroku

Asif Ahmed

In a previous post we have talked about using Heroku as a hosting platform for us. Often times Heroku is used with a Rails app, and most recently it has been used to host Node apps as well. Heroku, however, can also be used for hosting PHP apps. Let us cover how to use Heroku to host a incredibly simple PHP app (that doesn’t connect to a database). I am going to assume you have Git installed and understand how to use Git.

Before you can really get anywhere with Heroku, go to download the Heroku Toolkit from and register for a Heroku account.

For our purposes let us create a sample PHP page. Open a terminal and create a directory anywhere and open an index.php file and put the following in there.

<?php phpinfo(); ?>

Then from the command line, enter in the following commands:

git init
git add .
git commit -m 'initial commit'
heroku create
git push heroku master
heroku open

This will initialize a git repo, add all the files in the directory to the repo, commit those changes, create a Heroku app, push our repo to Heroku, and then open our Heroku app in our web browser. For example, you could check out my app here – . One thing to note however, is that Heroku seems to be using PHP version 5.3. The most current version (as of February 2014) is 5.5, but it seems that the most used version of PHP is 5.4. In one of the next couple posts, I’ll cover how to install PHP 5.4 on the LTS (long term release) of Ubuntu 12.04. I guess this older version of PHP could be a downside to using Heroku for hosting…but it’s hard to complain much with free.

If you make any changes to your repo and want to redeploy, this would be the chain of commands you would need to run:

git add .
git commit -m 'write a meaningful commit message'
git push heroku master
heroku open

Good luck with deploying your PHP app. We might explore how to use a database with PHP on Heroku soon.