Laravel | Host Laravel Application in Heroku

In this blog, we will learn how to host Laravel on Heroku.

Prerequisite

  • Basic Knowledge of Laravel & Heroku.
  • Basic Knowledge of GIT.
  • Make sure to have a (New) Laravel Application ready. (Get started)

Steps for Hosting Laravel in Heroku

  1. Install Heroku CLI.
  2. Initialize Git & Create Procfile.
  3. Create Heroku App & Set Laravel App Key.
  4. Deploy Heroku App.

Step 1: Install Heroku CLI

  • For Windows, download and install a standalone package from the official site.
  • If you’re using Linux, enter the below command in the terminal to install.
sudo snap install --classic heroku
  • For Apple, enter the below command in the terminal to install.
brew tap heroku/brew && brew install heroku

Step 2: Initialize Git & Create Procfile

  • Once Heroku is installed, enter below command to login in heroku.
heroku login
  • Navigate to application’s root directory, intitalize the git repo and commit all files.
git init
git add .
git commit -m "All Files Uploaded."
  • Create a file named “Procfile” and paste the below code. This contains the apache settings needed to host the Laravel Application in Heroku.
web: vendor/bin/heroku-php-apache2 public/
  • Now, add that file to git and commit it.
git add Procfile
git commit -m "Heroku Procfile Added"

Step 3: Create Heroku App & Set Laravel App Key

  • Create Heroku app, itbulls-laravel is the app-name. If you don’t provide any app-name, heroku will generate itself.
heroku create itbulls-laravel
  • We need to specify language build in heroku, to do so enter below command.
heroku buildpacks:set heroku/php
  • Get the APP_KEY from .env file and enter below command.
heroku config:set APP_KEY="APP_KEY"

Step 4: Deploy Heroku App

  • Once everything is ready, push commits to master. As soon as you commit to master, a build will be created by Heroku and deploy to the apache server. Open the Heroku app and see it in the browser.
git push heroku master
heroku open

So this is how we deploy a normal Laravel application to Heroku. Do Share your errors in the comments section if any! Stay tuned for more such posts.

Previous Post
Next Post

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − twelve =