Deploy Laravel Projects With Database For Free! (2024)

Mostafa Said

Posted on • Updated on

Deploy Laravel Projects With Database For Free! (3) Deploy Laravel Projects With Database For Free! (4) Deploy Laravel Projects With Database For Free! (5) Deploy Laravel Projects With Database For Free! (6) Deploy Laravel Projects With Database For Free! (7)

#laravel #tutorial #php #heroku

NOTE: 🚨HEROKU DOESN'T DO ANYTHING FOR FREE ANYMORE🚨

Good day everyone 👋

In this article i'm going to explain how to host and deploy your Laravel project free on Heroku step by step, and it will work.

Let's get to it?

0- I'm using:

  • Laravel 8.8
  • PHP 8
  • Windows Terminal
  • GitHub
  • Git Commands
  • Heroku Toolbelt

Before you continue reading, Heroku announced that they will no longer support any free products :(

1- Install Nodejs and npm:

  • First thing you need to make sure that you have Node and npm installed on your machine.
  • You can check that by opening up the terminal and type those two commands:

npm -v
node -v

PS C:\Users\Moose> node -vv16.13.2PS C:\Users\Moose> npm -v8.4.0

2- Start your Laravel Project:

  • If you already have a project, you can skip this step 👇.
  • I use composer to create Laravel projects.
  • You can download composer from here: https://getcomposer.org/
  • Open up your terminal and create your Laravel project in the desired directory.
  • I already have Laravel project created but here is the terminal command to create a new project via composer.
  • Instead of 'example-app' just name your project.
PS C:\Users\Moose> composer create-project laravel/laravel example-app

3- Create Account and Download Heroku Toolbelt:

  • Sign up for a free account on Heroku from HERE. If you already have an account, move on to next step 👇
  • For the sake of keeping everything simple and smooth, download Heroku Toolbelt for free from 🔗 HERE.
  • Just keep pressing next and leave everything to default.

4- Procfile Creation:

  • Now we need to add a new file to our project in the main directory.
  • Head to your project folder and create new file and name it Procfile without extension and insure that first letter is in uppercase.
  • Inside the file, leave the below code and then save.
web: vendor/bin/heroku-php-apache2 public/

  • Just like this 👇Deploy Laravel Projects With Database For Free! (8)

5- New to GitHub? :

  • I'm sure you have GitHub account but if you don't, you need to create one and connect to it.
  • Since this is not GitHub tutorial, please visit the following LINK for a complete guide how to create GitHub account.
  • Also if you're new to Git, don't forget to setup your username through terminal. Visit this LINK to know how.

6- Git:

  • You can skip this if you already have a Laravel project and it is on GitHub. In this case all you need to do is to push the changes with Procfile to GitHub normally.
  • Assuming you're creating a new repo for your project. Open you terminal in the project directory and type the below commands in the same order one by one.
  • Please note that in my case, PS F:\Projects\Zarafah> is my project main directory path.
PS F:\Projects\Zarafah> git initPS F:\Projects\Zarafah> git add .PS F:\Projects\Zarafah> git commit -m "initial release"

7- Create Heroku App:

Please follow carefully for best results.

  • Open you terminal in the project directory and type the below commands in the same order one by one.
  • In command number 4, you'll find that i'm renaming my app to 'zarafah'. You can name it whatever you want but it is recommended to name it exactly the same name on github.
PS F:\Projects\Zarafah> heroku createPS F:\Projects\Zarafah> git remote rm herokuPS F:\Projects\Zarafah> heroku createPS F:\Projects\Zarafah> heroku rename zarafah

  • Time to push this project to heroku.
PS F:\Projects\Zarafah> git push heroku master

8- Setting Up Heroku App:

  • Now, if we try to open app through Heroku it will get us error 500.
  • Open up Heroku Dashboard and follow the below path:

Select your project - Select settings - Scroll down and click on 'Reveal Config Vars' - You will find one input for key and other for value.

  • Head to your project main folder and open your .env file.
  • Look for the below.Deploy Laravel Projects With Database For Free! (10)
  • Copy 'APP_DEBUG' and insert it in key input and copy 'true' and insert it in value input.
  • Do the same for 'APP_KEY' and it's value.

9- Adding to Heroku Config:

  • Have your .env file open.
  • Open the terminal in your project directory and hit the below commands.
  • In the terminal we will write heroku config:add (key value) and then we add a space and give the key and value.
  • Find an example below but keep in mind that the values are set according to your .env file.
  • For app Env, make sure to insert the value 'production'.
PS F:\Projects\Zarafah> heroku config:add APP_NAME=ZarafahPS F:\Projects\Zarafah> heroku config:add APP_ENV=production

  • In APP_URL, insure to copy the url for your app from Heroku.
  • In my case 👇
PS F:\Projects\Zarafah> heroku config:add APP_URL=https://zarafah.herokuapp.com/

10- Setting up DataBase in Heroku:

By now if you don't have any database connections in your Laravel project, your app show open and work on Heroku normally 🥳🥳

In case you do have Database connections like me, continue 👇

  • Head to Heroku Dashboard.
  • Press on your App.
  • Click on 'Resources'
  • Search for 'heroku postgres'
  • Click 'Provision'.Deploy Laravel Projects With Database For Free! (11)

Next step is very important, we're going to get our add-on credentials from heroku and update them one by one.

  • Open up the terminal in your main project folder.
PS F:\Projects\Zarafah> heroku pg:credentials:url

  • You will get a response with all the credentials and we will be adding them one by one.
  • Have your .env file open.
  • We will copy the keys from .env file and the values from the response we got from the terminal.
  • In the below example i'm just going to write down '...' instead of the actual credentials.
PS F:\Projects\Zarafah> heroku config:add DB_CONNECTION=pgsqlPS F:\Projects\Zarafah> heroku config:add DB_HOST= ...PS F:\Projects\Zarafah> heroku config:add DB_PORT= ...PS F:\Projects\Zarafah> heroku config:add DB_DATABASE= ...PS F:\Projects\Zarafah> heroku config:add DB_USERNAME= ...PS F:\Projects\Zarafah> heroku config:add DB_PASSWORD= ...

11- Migration and seed:

  • Now we can migrate with our new Database.
  • Note that you can't migrate your --seed since Heroku add-on doesn't support Laravel Factory.
  • Run the below code to proceed with your migration
PS F:\Projects\Zarafah> heroku run php artisan migrate

12- Finishing:

Congratulations your Laravel project is now live on Heroku with database for free 🎉🥳

You can visit the app with the url that heroku created.

This is a great opportunity for you to test your app and see it going live and share it with others.

If you have any questions please ask me in the comments below or find me on Twitter

Thank you for reading ❤️

Top comments (9)

Subscribe

Vincent

Vincent

The great square is cornerlessThe great vessel is last complete,The great note is rarified sound,The great image has no form.

  • Joined

Aug 11 '22

  • Copy link

very nice tuto but im stuck n databse part im running y laravel under mysql but you used postgres

Mostafa Said

Mostafa Said

I’m Mostafa, full-time VueSchool instructor and a fullstack developer

  • Email

    mostafasaid1994@gmail.com

  • Location

    Cairo, Egypt

  • Work

    Full time instructor @VueSchool

  • Joined

Aug 31 '22

  • Copy link

Well, Heroku didn't have free mysql support. Now heroku doesn't have anything free :(

AhmedZake33

AhmedZake33

  • Joined

May 31 '22

  • Copy link

Forbidden
You don't have permission to access this resource.

Muhammad Khan

Muhammad Khan

  • Email

    muhammadkhan1607@gmail.com

  • Location

    Lahore, Pakistan

  • Work

    Software Engineer at TechHive

  • Joined

Jun 5 '22

  • Copy link

You may have missed the Procfile, I did the same and got the same error.

Mostafa Said

Mostafa Said

I’m Mostafa, full-time VueSchool instructor and a fullstack developer

  • Email

    mostafasaid1994@gmail.com

  • Location

    Cairo, Egypt

  • Work

    Full time instructor @VueSchool

  • Joined

May 31 '22

  • Copy link

I'm not following. Where did you encounter this error?

nikhil cb

nikhil cb

  • Joined

Jul 1 '22

  • Copy link

it worked, thank you

Mostafa Said

Mostafa Said

I’m Mostafa, full-time VueSchool instructor and a fullstack developer

  • Email

    mostafasaid1994@gmail.com

  • Location

    Cairo, Egypt

  • Work

    Full time instructor @VueSchool

  • Joined

Jul 1 '22

  • Copy link

You're most welcome 😊

Mohamad Houmani

Mohamad Houmani

  • Joined

Aug 2 '22

  • Copy link

Hello, what about this error I got
Running php artisan migrate:refresh on ⬢ myappname... up, run.1124 (Free)
bash: php: command not found

Mostafa Said

Mostafa Said

I’m Mostafa, full-time VueSchool instructor and a fullstack developer

  • Email

    mostafasaid1994@gmail.com

  • Location

    Cairo, Egypt

  • Work

    Full time instructor @VueSchool

  • Joined

Aug 31 '22

  • Copy link

I will need more information to help you.

For further actions, you may consider blocking this person and/or reporting abuse

Deploy Laravel Projects With Database For Free! (2024)

References

Top Articles
Tour the North Carolina Places That Inspired ‘The Longest Ride’
The amazing setting and backstory of The #LongestRide Movie
San Angelo, Texas: eine Oase für Kunstliebhaber
35105N Sap 5 50 W Nit
Mndot Road Closures
Culver's Flavor Of The Day Monroe
A Fashion Lover's Guide To Copenhagen
ATV Blue Book - Values & Used Prices
‘Accused: Guilty Or Innocent?’: A&E Delivering Up-Close Look At Lives Of Those Accused Of Brutal Crimes
Shreveport Active 911
Tcu Jaggaer
065106619
Are They Not Beautiful Wowhead
Jalapeno Grill Ponca City Menu
CDL Rostermania 2023-2024 | News, Rumors & Every Confirmed Roster
Scout Shop Massapequa
*Price Lowered! This weekend ONLY* 2006 VTX1300R, windshield & hard bags, low mi - motorcycles/scooters - by owner -...
Robeson County Mugshots 2022
Aerocareusa Hmebillpay Com
Myhr North Memorial
Conscious Cloud Dispensary Photos
Understanding Gestalt Principles: Definition and Examples
Lines Ac And Rs Can Best Be Described As
Prey For The Devil Showtimes Near Ontario Luxe Reel Theatre
Roanoke Skipthegames Com
1773x / >
Healthy Kaiserpermanente Org Sign On
Ups Drop Off Newton Ks
R/Sandiego
Used 2 Seater Go Karts
Yoshidakins
Ixl Lausd Northwest
Justin Mckenzie Phillip Bryant
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
Moxfield Deck Builder
Weapons Storehouse Nyt Crossword
Tokyo Spa Memphis Reviews
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Los Garroberros Menu
Jasgotgass2
Weather Underground Corvallis
Shoecarnival Com Careers
Charli D'amelio Bj
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
Disassemble Malm Bed Frame
60 Days From May 31
Port Huron Newspaper
Keci News
Big Brother 23: Wiki, Vote, Cast, Release Date, Contestants, Winner, Elimination
The 5 Types of Intimacy Every Healthy Relationship Needs | All Points North
What your eye doctor knows about your health
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6594

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.