Laravel: Deploy Laravel Projects On Heroku

Deploy, Build, Run, and Operate Laravel Applications On Heroku Cloud Application Platform

Posted on February 24, 2017 in Laravel Tutorials
Heroku Cloud Application Platform is a Platform as a Service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.

Heroku is a public PaaS (Platform as a Service) provider that makes it easy to deploy applications written using several technology stacks for absolutely free. Application developers all around the world use Heroku-like services to deploy and test their applications remotely. In this tutorial, let’s see how we can deploy our awesome web application on Heroku with few easy steps.

(01) Setup Heroku CLI

The Heroku Command Line Interface (CLI), formerly known as the Heroku Toolbelt, is a tool for creating and managing Heroku apps from the command line/shell of various operating systems. First of all, create a Heroku account, download Heroku CLI, and configure Heroku Toolbet to use on your local machine. Instructions to download and setup Heroku CLI are available here.

(02) Create Heroku App

To deploy our project on Heroku, we first need to create an app on Heroku (It’s like creating a repo on GitHub). There are 2 ways of doing it; you can either run heroku create myawesomeapp on your terminal or create a new app manually using the Heroku Dashboard web interface.

(03) Create Procfile On Root Directory Of Project

A Procfile is a mechanism for declaring what commands are run by your application’s dynos on the Heroku platform. It follows the process model. You can use a Procfile to declare various process types, such as multiple types of workers, a singleton process like a clock, or a consumer of the Twitter streaming API.
Source: Process Types and the Procfile

A Procfile is a file named Procfile. It should be named Procfile exactly, and not anything else. For example, Procfile.txt is not valid. The file should be a simple text file. Also the file must be placed in the root directory of your application. It will not function if placed in a subdirectory.

Now you may have a problem on how to create a file which is exactly named Procfile. Use your favorite code editor (e.g. Sublime Text, Visual Studio Code), create a new file, include the following line as the content of the file, and save the file as Procfile.

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

(04) Modify composer.json

Now open composer.json file in your root directory. Now find the following lines;

"require": {
      "php": ">=5.6.4",
      "laravel/framework": "5.4.*",
      "laravel/tinker": "~1.0"
"require-dev": {
      "fzaninotto/faker": "~1.4",
      "mockery/mockery": "0.9.*",
      "phpunit/phpunit": "~5.7"

Under require-dev, you are seeing libraries and packages that we use only during the development stage. As long as we keep the APP_ENV as local, Laravel will read and download packages under both require and require-dev. But in the production environment, Laravel only reads packages under require. Since we are not done with the development yet, let’s modify these lines as follows, so that we can get all packages running on Heroku as well.

"require": {
      "php": ">=5.6.4",
      "laravel/framework": "5.4.*",
      "laravel/tinker": "~1.0",
      "fzaninotto/faker": "~1.4",
      "mockery/mockery": "0.9.*",
      "phpunit/phpunit": "~5.7"
"require-dev": {
      "fzaninotto/faker": "~1.4",
      "mockery/mockery": "0.9.*",
      "phpunit/phpunit": "~5.7"

(05) Get Your Project Files Up-to-date

If you are happy with the package versions mentioned in the composer.json file, run composer install. If you want to update those package files to the latest, run composer update. Note that sometimes updating packages can result in problems in your code because of the new changes in the packages. Therefore, be mindful about the possible results before updating package versions.

(06) Add Your Project Files To Heroku

Now we are done with local modifications. You have 2 easy methods to deploy your project on Heroku;

a) Connect to a GitHub branch and enable auto deployment on Heroku (this is the method I recommend for developers)

To do this, first you have to commit your local changes and push the latest to your remote repo on GitHub using git push origin master command. You can choose a separate branch for deployment purposes if you like. Now go back to Heroku Dashboard web interface, open your app, select Deploy, Under Deployment Method select GitHub, log into your GutHub account, choose the repo and deployment branch. If you prefer automatic deploys, enable that option too. Otherwise you will have to visit the Heroku Dashboard and manually deploy the project each time you make changes to you GitHub code. If necessary, select the buildpack as PHP.

b) Push your project files to Heroku using Heroku CLI

To do this, first you have to commit your local changes and push the latest to your remote Heroku app using the following command;

git push heroku master --app myawesomeapp

Also to select the buildpack, run the following command on your terminal;

heroku config:add BUILDPACK_URL= --app myawesomeapp

To check whether our project is running, run the following command on your terminal and it will open up your browser with your web application.

heroku open --app myawesomeapp

(07) Setup Database Connections

Although Heroku creates a platform for your app to run, it does not provide database connectivity. Therefore we have to find a way on our own. This is one of the major drawbacks in using a platform like Heroku. But since it gives many things for free, developers still love this platform a lot.

So the good news is, we have a plan B. Let’s use a free MySQL database provider and connect our Heroku application to use its database. Just google for free MySQL hosting and you will get tons of results. For this tutorial, I am gonna try my second google result:

You will probably have to create an account, provide database name, database password on the selected site. When you provide information with these external database services, it is highly advised not to share any sensitive information because these services are normally provided for education and testing purposes, so that the protection for your data can be really low.

After creating your free MySQL database, you will receive information about the database. Go to your local project folder, open config/database.php file, and update it with your remote database details as follows,

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', ''),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'myawesomeappdb'),
            'username' => env('DB_USERNAME', 'awesomedbadmin'),
            'password' => env('DB_PASSWORD', 'You-Can't-See-Me'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,

Now we have to apply these changes in Heroku app as well. If you have enabled the automatic GitHub deployment, you just need to commit changes locally and update the deployment branch by running

git push origin master

command. Otherwise you can use Heroku CLI. Just open your terminal and run the following command;

git push heroku master --app myawesomeapp

Now your Heroku app is updated with the information of your remote database.

(08) Create Database Tables and Seed Data

Run the following 2 commands on your terminal to establish your database tables;

heroku run php artisan migrate --app myawesomeapp

heroku run php artisan db:seed --app myawesomeapp

Now your Laravel application is ready to use on Heroku. Go to and enjoy the functionality of your Laravel application. Happy Laravelling folks!!

comments powered by Disqus