How to manually deploy a laravel application on heroku using Git

Deploy Laravel App on Heroku Using Git

If you’re reading this article, it’s assumed that you already have an idea of what Laravel and heroku is all about.

Quick Recap
Laravel is an open source php based framework that allows you to build a fast and scalable web application using the Model View Controller (MVC) architectural pattern. It offers flexibility with plain php while working with it. Currently, Laravel has over 400, 000 Github stars and it’s widely used in the whole universe.

Heroku is a cloud-based platform as a service (Paas) allow you to deploy a fast, reliable and real-time web application. It supports Java, Nodejs, PHP, Scala, Python, Go, Clojure, Ruby and many more programming language. It is said to be a polyglot platform as it lets the developer build, run and scale applications in a similar manner across all the languages.

Prerequisite
1. Already existing Laravel application.
2. A Heroku account, create one here if you don’t have
3. Git Installed on your pC
4. Terminal or Command Prompt for windows users

Getting Started

Having installed Composer, Git, Npm, Nodejs on your pc, download and install the Heroku installation file for 32 Bits or 64 Bits version of your PC or you can install using the npm cli code below.

npm install -g heroku-cli

After successful installation. Start your command prompt and type Heroku you should see something like the image below

Testing Heroku Installation

Wow…. Heroku is Live on your PC !!!

Next is to login to Heroku via the command line using your login. Type Heroku login, you’ll be prompted to enter your email and your password as shown below.

Next is to navigate to your Laravel folder directory (I call my own deployToHeroku)and type “Heroku create deploy-laravel-to-heroku”. Heroku creates the app and provides the app git url “https://deploy-laravel-to-heroku.herokuapp.com/ | https://git.heroku.com/deploy-laravel-to-heroku.git”. These are the URL to access and push to Heroku cloud. If you login to your Heroku account, you’ll find the newly created app on your dashboard.

Next is to add the Laravel files into Heroku cloud storage using the git url. Enter the following code
git init
git add *
git commit -m "Initial Deployment to Heroku"
heroku git:remote -a deploy-laravel-to-heroku
git push heroku master
heroku open

Don’t forget to remove the “.env” file from .gitignore else your laravel application won’t come up

Heroku permission error

We got this error because we have not been granted permission to the public directory yet. Type in the code below while in your Laravel root folder

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

git add *
git commit -m "Added Heroku Procfile"
git push heroku master
heroku open

Added Heroku Procfile and pushing to the cloud

If you get the Laravel error,

heroku run php artisan key:generate

Yhuppy your site is live !!!

Check it out over here https://deploy-laravel-to-heroku.herokuapp.com

Site up and running

Please don’t forget to share and follow me on twitter.com/samalapsy

Thank you for reading.

--

--