Make your Laravel Project Live

Introduction

We will be using Heroku free tier to deploy our Laravel application. Heroku is free for some extent and that’s enough for us. We can do our deployment without putting any money.

Heroku is a SalesForce company

  • First, we will create one free Heroku account
  • We will install Heroku CLI
  • We will install git CLI (if not installed)
  • We will create one new Laravel Project and add git
  • We will create one heroku application
  • We will configure laravel app for heroku
  • We will finally deploy

Creating Heroku Account

Go to https://signup.heroku.com/ and create your free heroku account. If you already have the account then you can skip this step.

You don’t require Credit card detail in order to get free account

Installing Heroku CLI

To install Heroku CLI, go to https://devcenter.heroku.com/articles/heroku-cli and follow the instructions.

Heroku CLI is available for all three major OS

  • Windows
  • Mac
  • Linux

If you are using any other OS then you might face some problem.

Installing git CLI

To download git CLI go to this website https://git-scm.com/downloads.

git CLI is also available for all three major OS

  • Windows
  • Mac
  • Linux

After Installing GIT CLI you need to do some minor setup which is

git config --global user.name "Your Name"
git config --global user.email your_email@gmail.com

Creating new laravel project

If you are reading the probably you know how to install laravel project. So, I will not talk about the laravel project creation.

Creating new heroku project

To create new heroku project run this command.

heroku create

This will say you that No account Configured press any key to do so or press q ro quit.

You press any key to configure CLI with your account. This will open your default browser and HEROKU will ask you for your credential. As soon as you enter the correct credential it will authenticate the cli with your computer.

Now you cli knows who you are and it will create one project for you.

Configure Laravel app for Heroku

First we will tell the heroku about the public directory of the app. So that Heroku will know which is our public directly for serving on the internet.

echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile

Now we will set the APP_KEY, while doing local development we don’t need to do this because laravel read that from .env file but in the production we need to set in the environment variable.

heroku config:set APP_KEY=$(php artisan --no-ansi key:generate --show)

Finally deploymeny

This will deploy the Laravel application to the heroku server.

git init 
git add .
git commit -m "initial commit"
git push heroku master