I would like to start my blog with the question “why” as there are lots of technologies to choose from that are maybe better and more convenient to use but after all, it’s all about personal preferences.
So why Heroku?
Heroku is a public PaaS (Platform as a Service) provider that makes it easy to deploy applications written using several technology stacks at no cost. Application developers all around the globe use Heroku-like services to implement and test their applications remotely without any pain.
It’s free and easy to use.
Prepare your Laravel app
On this tutorial, I will use the repo : https://github.com/rappasoft/laravel-boilerplate. Laravel Boilerplate provides you with a massive head start on any size web application. It comes with a full featured access control system out of the box with an easy to learn API and is built on a Bootstrap foundation with a front and backend architecture. A big thanks to all who made contributions to this open source laravel app. Go ahead, fork and clone that repo or you can use your own depending on your preference.
I assume you tested your app on local and everything worked fine before proceeding to set up the heroku.
Prepare your Heroku CLI
You can download heroku-cli at:
Download and install Heroku according to your OS.
Once installation is finished, go back to your terminal and try to execute:
Create Procfile inside your main Laravel
Inside your Procfile, put this code line.
web: vendor/bin/heroku-php-apache2 public/
Go back to your terminal and type:
git init - This is for git initialization
heroku create - This command will create your app and repository name in Heroku
After that, commit and push your project to Heroku.
This will give you a 500 server error because we have not set any configuration from our .env file on our Laravel app into Heroku.
Add Config Vars setttings in Heroku
Lastly, we will configure our database so that we can run migrations and seeders in Heroku. Actually, we can use MySQL but we need to upgrade our membership. That’s why in this tutorial, we will be using PostgreSQL because it’s free. :)
Click install Heroku Postgres. After successful installation, heroku postgres is available in our dashboard resources just like below.
After that, go to your terminal and type:
Take note on your DATABASE_URL.
On your laravel app go to config/database.php file, and put this code on the top.
Now, we will commit and push our changes in heroku repo. In your terminal run these commands below.
git add .
git commit –m “update db connection”
git push heroku master
Then, run migration in heroku.
Then access your heroku app
There you have it! You now have a running laravel-boilerplate app with database deployed in heroku.
Hopefully this tutorial is useful to you.
Ending this tutorial with something I read last night which I think is worth sharing. 🙂