Host your laravel application on Heroku

Rohit urane
3 min readJul 23, 2022

--

Hi guys,

Do you want to host your laravel application on Heroku? Here we go with this article. You are going with a new setup of the laravel application. Click Here to check the laravel application after done all steps.

Creating Laravel application on Local System

First, I am installing the laravel application on the local development system through composer.

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

Make Procfile inside the root folder of your project

After completing the installation, create a file of the name Procfile and insert the below code. This file is a configuration file for Heroku.

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

Download and login to the Heroku platform from the command line

For that, you need to install Heroku CLI on your system. Go to the Heroku platform and download & install it. Click Here. Run the below command inside your project folder.

heroku login

It will open a browser window to log in to Heroku. If you don’t have an account on Heroku, create it first.

Push code on GitHub

We are using GitHub for version control. For that, we initialize the git repository and push the code on GitHub using the following command:

git init 
git add .
git commit -m "Initial commit."

Create App on Heroku and push code

You can create an app on the Heroku platform through command. See the image below.

heroku create

You can push code on the Heroku app through the below command. It will set up everything for your project.

git push heroku master

Fix Laravel Heroku 500 Message

Login on the Heroku platform. Select your App on the Heroku platform and go to the setting tab. Click the Reveal Config vars button. Add below key value on config vars.

APP_KEY=base64:skjC/s+cDyHMcrLi0d60bc33CU9ee0+sugwLESN+wZo= APP_DEBUG=true

Check your app link. It works.

Add Config variable to Heroku app through command line

There are two ways to add config variables -
(1) Through the Heroku platform: I have shown this above step.
(2) Through Heroku CLI: You can add configuration variables through the command line for the Heroku app. you can see below the command.

heroku config:add APP_NAME=herokuApp 
heroku config:add APP_ENV=production
heroku config:add APP_URL=https://lit-escarpment-79303.herokuapp.com/

Configure the Database to the Heroku app

Go to the Resources tab inside the Heroku platform. Search inside Add-ons “postgre” PostgreSQL is like the MySQL database. I am using a free service from postgre “Hobby Dev” You can get credentials from the Heroku platform.

heroku pg:credentials:url 
heroku config:add DB_CONNECTION=pgsql
heroku config:add DB_HOST=ec2-52-234-157-26.compute-1.amazonaws.com heroku config:add DB_PORT=5432
heroku config:add DB_DATABASE=db07hqnreuvi5q
heroku config:add DB_USERNAME=udbsxvagrztnjx
heroku config:add DB_PASSWORD=39701181fb504bd38632ea748456f4a29798d27c9e2d2d0b07c113515e4a5e6

Migrate the database for your application

Now, we are going to migrate to the database. It will generate all tables.

heroku run php artisan migrate

Goto Resources tab, click Heroku Postgre Add-ons. It will show a database summary.

Upload changes on Heroku

Every time you change in the code repository. You commit to the Heroku platform. Below are the steps to carry out the source code.

git add . 
git commit -m "{commit message}"
git push heroku master

You can check the project link:- ( https://lit-escarpment-79303.herokuapp.com/)

Now your application is ready to use on any browser. Check the CRUD operations of your application.

Now your user will easily connect to your application. Do you want to check which mail tools are best for your application? Click Here. I hope that this post (Host your laravel application on Heroku) has clarified how to integrate the socialite package in laravel and load the drivers. If you have questions, please leave a comment and I will respond as soon as possible.

Thank you for reading this article. Please share this article with your friend circle. That’s it for the day. Stay Connected!
Cheers

Originally published at https://www.devrohit.com on July 23, 2022.

--

--

Rohit urane
Rohit urane

Written by Rohit urane

enthusiastic full stack developer to build application

No responses yet