Laravel Application Deployment on Heroku

After creating heroku account run the following commands on ubuntu terminal to install Heroku CLI.

1. Install Heroku

# Run this from your terminal.
# The following will add heroku apt repository and install the CLI:
sudo add-apt-repository "deb ./"
curl -L | sudo apt-key add -
sudo apt-get update
sudo apt-get install heroku

The setup instructions for heroku on other OS are available here. Next, login to your Heroku account:

heroku login

Before proceeding further please check if php, composer and git are installed in your system.

php -v
composer -V
git --version

2. Add Procfile

Clone your git repository and create a ‘Procfile’ in root directory of your project. The content of Procfile will be following:

web: vendor/bin/heroku-php-apache2 public/

Procfile is needed because apache2 default process points to web root instead of /public folder where index.php resides for laravel. If this step is skipped then after application deployment browser will show the following error message:

3. Create an App

Next, create an app on Heroku:

heroku create [app-name]

Link your local repository with heroku app, created in previous step:

heroku git:remote -a [app-name]

Deploy your code on heroku.

git push heroku master

After app deployment set the app-key. The app-key should be set to 32 character string.

heroku config:set APP_KEY=[app-key]

4. Add the Database

You can select any database from here as per your requirement. Adding PostgreSQL to the app:

heroku addons:create heroku-postgresql:hobby-dev

I have not used MySql because it needs heroku account verification with credit card.

Database can be accessed by:

heroku pg:psql

Next, run the laravel migrations.

heroku run php artisan migrate

* Troubleshoot Errors

If laravel is upgraded from 5.0 to 5.2, then change ‘cipher’ in config/app.php from:

'cipher' => MCRYPT_RIJNDAEL_128,


'cipher' => 'AES-256-CBC',

To check the error set APP_DEBUG to true:

heroku config:set APP_DEBUG=true

To remove the heroku reference from your project folder.

git remote rm heroku

To remove database associated with application:

heroku addons:destroy heroku-postgresql:hobby-dev

The detailed explanation to deploy PHP app on Heroku are available here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s