Qasim Nadeem
Nov 3 · 4 min read

Install Git on you machine if you do not already have it installed.

I am assuming that you already know Git and have it installed on your machine, if not use following commands on your Linux terminal to install git.

sudo apt-get update

sudo apt-get install git-core

For checking if it is installed use command:

git — version

Note: for installing git on Windows or mac you follow these Atlassian Guide links bellow:

For Windows: https://www.atlassian.com/git/tutorials/install-git#windows

For Mac: https://www.atlassian.com/git/tutorials/install-git#mac-os-x

Initialize your project directory with git if you do not already initialized it.

Move into the directory where you have your Laravel project code placed, using terminal, and run following command:

git init

Your repository is now able to use git. You also need to set your username and email for this repository otherwise you will not be able to push you code. Use following commands for setting username and email.

Git config user.name sam

Git config user.email sam@medium.com

Note: You can replace “sam” and “sam@medium.com” with any username or email of your choice.

Install heroku-cli on you machine

First you need to create your account on heroku visit www.heroku.com and signup for a new account if you do not already have one.

Go to your Linux terminal and write following command for installing heroku:

sudo snap install heroku — classic

For installation on mac you can use brew and write following command to install it:

brew install heroku heroku/brew/heroku

For installing on windows you can download installer from following link:

For 64 bit installer : https://cli-assets.heroku.com/heroku-x64.exe

For 32 bit installer : https://cli-assets.heroku.com/heroku-x86.exe

After installing Heroku, again move to terminal and use following command to login with Heroku:

heroku login

Above command will automatically open a page on your browser to login. You can close this page after login and go back to terminal you will see a message that you have successfully logged in.

Add Heroku to your project directory

Now move to the directory where you have your Laravel project, and run command:

heroku create

Push Laravel code to Heroku

Again inside your project directory run following command to push your master branch code to remote heroku.

git push heroku master

Also use following command to ensure that at least one instance of the app is running on the server:

heroku ps:scale web=1

Your project is deployed on the heroku server and you can open your application using the following command:

heroku open

Note: a simple PHP project without any database can be deployed using the above instructions but, as every Laravel project have a database, its configuration(.env file) and also migrations, so we have to do some extra steps for configuring the database.

Configuring database for Laravel project on Heroku

Installing Plugin for database

Login to your heroku account from your browser, on the dashboard you will see your project is listed there. Click on it, and then in top navigation bar you will see a link named resources. Click on it. There will be a search bar for searching Add-ons, type “mysql” here, and select: JawsDB Mysql form search result.

Installing plugin for MySQL Database

After that, a popup will show up, select a free package from drop down or any premium package if you want more database space. Free option will only give you 5mb database space, that’s enough to deploy an app with small data, after that just click on the provision button.

Note: after clicking on the provision it may ask you to add payment method even if you selected a free package. You can add any of your card that you use for online transaction no money will be deducted.

Adding Database configuration

Click on the name of the plugin that you have just installed under resources. It will open a new tab showing all your database information: DB_Name, server, passwords etc.

Creating Config Vars

Now click on the settings link on top navigation. Under config vars section click on “Show config var” or “Add config var” Add all your Config vars as in your. You can use APP_KEY that is in your project .env file other vars values will be in JawsDB page that you opened after clicking on JawsDB plugin name.

Set your config vars

Run the migrations

To run Laravel migrations, click on more at the top right corner, and then click on “run console” link. Inside the text box write command:

php artisan migrate

Press y and enter if it asks for your assurance.

After all your migrations run successfully you are all set. Your project is deployed. You can click on open project button at the top right corner, to see your application.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade