How to deploy your Laravel app on Heroku for free

In this blog post, I will teach you how to put your Laravel app / site onto Heroku (using the browser interface) for free. Since Hosting on Heroku is free, this is ideal for hosting any of your projects in your portfolio. Let's get started.

Sign in to Heroku

First, sign up or sign in to Heroku. In the Heroku Dashboard, you will see a button "New". Click on this button and then "create new app".

Give your app a name. Whatever name you choose will become part of the URL of the app. So if you name the app: my-clone-project, then the URL will become my-clone-project.herokuapp.com.

Also, choose whichever region you want.

How to deploy Laravel app to Heroku

In this tutorial, I will show you how to do it directly through the browser (instead of through the CLI).

Before we start, make sure you have the project in a Github repo.

Procfile

  1. In the root directory of your project, create a file called Procfile. In this file paste this in web: vendor/bin/heroku-php-apache2 public/. This is a configuration file for Heroku.

  2. Now commit this change and push it to your Github repo. Quick example: git add . , git commit -m "add procfile", git push origin master.

Github integration

  1. Now that you have the procfile, you need to click on the deploy tab in the Heroku dashboard. Where it says Deployment method, choose github.

  2. Sign in and then search for the repo of the project. Then connect to it.

    Heroku Dashboard connecting to Github

  3. Scroll down to the Automatic deploys section and Enable automatic deploys. This makes it so that "Every push to master will deploy a new version of this app. Deploys happen automatically".

  4. Scroll to Manual Deploy and deploy branch. It's not really going to work yet since we haven't set up the environment variables or the database. This is just to make sure everything builds and installs correctly.

Database addon

  1. Click on the Resouces tab. In the add-ons section, search for JawsDB MySQL and choose the free plan. This is the free database I will be using. Click it, and it should open a new tab with a jawsdb dashboard. Keep this tab open.

Setting up env variables

  1. Click on the Settings tab. Then click on reveal config variables.

App env

  1. Now you will put the environment variables. Open your .env file in your project to see which ones you need. Take a look at my pic and replace my specific values with yours.

    Replace the APP_KEY with your own from your .env file. Make the APP_NAME to what you want your app name to be. The APP_URL will be what you named your app followed by .herokuapp.com. For example, mine is https://questionnaire-app-clone.herokuapp.com/.

    Heroku app env vars

DB env

  1. Now we will be adding the database env variables. Please see the pic and replace the values accordingly. All the correct values you will be getting from the jawsdb dashboard. If you closed the tab, open it again in the Resources tab and clicking the jawsdb add on or go to the jawsdb dashboard.

    Heroku db env vars

Checking if it all works

  1. Click on More (near the top) and then Run Console.

    Heroku run console

  2. Type in php artisan migrate (if you need to do any seeding, do it here too). If it's a success, it should look like my screenshot.

    php artisan migrate command in Heroku console

That's it!

Your application should now be working. Click on Open App in your heroku dashboard to see it in action. Play around and create users, etc, to make sure it all works.

To administer the database, I recommend something like tableplus or mysql workbench.

Keep in mind that, with this free database, we can’t name our database. So if any of your SQL queries in the app contain the database name, you will need to switch it.

In case you want to see the app I deployed, it's here questionnaire app.

Make one page websites quickly using my Carrd Templates