Laravel Project Deployment On Heroku

Nifla Fareed
Nerd For Tech
Published in
3 min readJun 10, 2021
Designed by vectorjuice / Freepik

Heroku is a cloud computing application that provides Platform as a Service (PaaS). This platform allows developers to deploy, manage, and scale their applications. In this article, I will show you how to deploy a laravel project on the Heroku platform.

Let's get started.

Install heroku CLI

As a first step, you should install heroku CLI on your PC. Check this link and Install Heroku CLI according to your operating system.

Create a laravel project

Create a fresh laravel project locally by running the following command.

composer create-project --prefer-dist laravel/laravel laravelonheroku

Initialize a Git Repository

Initialize a git repository in your laravel project folder using the following command.

git init

Create a Procfile

Inside your laravel project create a file named Procfile and add the following code inside your Procfile.

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

Create Heroku App

Create a Heroku app by running the following command. Note that you should have an account in Heroku, if you do not have an account create an account before running the below command.

Create an account on Heroku

heroku create

An application will be created with a random name. In my case, the application name is “thawing-atoll-02946”

Screenshot by Author

You can rename it using the command given below.

heroku apps:rename <newname>

Setup Laravel encryption key

To set up and get laravel encryption key run:

php artisan key:generate --show

Once you run the above command you will get the key. Copy the key and run the command given below.

heroku config:set APP_KEY=<copied key>

Push the changes

You have to push all the changes that you made locally, to the git repository.

Run following commands one by one to push the changes to the Heroku server.

git add .
git commit -m"<message>"
git push heroku master

Configuring Database

To implement login and registration you should set up the database in the heroku server. In my project, I will use Postgres Database, because It is free on Heroku.

Run the following command to create Postgres SQL for your application.

heroku addons:create heroku-postgresql:hobby-dev

Now go to the database.php file(inside config folder in your project), change mysql into pgsql as your default database.

your database.php file should look like this.

As you have made changes in the database.php file, you must push the above change to the git repo by running the following commands one by one.

git add .
git commit -m"<message>"
git push heroku master

Now you can run the migration. run the following command to migrate your database.

heroku run php artisan migrate

Set up Authentication

As laravel provides authentication tools you can set up a login and registration system by running the following commands.

composer require laravel/ui
php artisan ui:auth

push the changes to heroku server

git add .
git commit -m"<message>"
git push heroku master

Now you can successfully register and login into your deployed laravel application.

Hope you found this article helpful. Thank you for reading!

--

--

Nifla Fareed
Nerd For Tech

Software Engineer @ IFS | Graduated from University of Moratuwa, Sri Lanka