Deploy a Laravel 5 app to Heroku
Heroku is an awesome platform originally built on top of AWS and currently owned by Salesforce. Laravel is a powerful PHP web framework for building applications.
In this short tutorial we’re going to generate an app from laravel-5-boilerplate and deploy it to Heroku.
By the end of the tutorial we will have a user management and permission system built with Laravel, Bootstrap and live to the internets powered by Heroku.
If you prefer to have a generic Laravel 5 app instead of a massive boilerplate follow this gist. Besides step 1 everything else will be the same.
Without further ado, let’s get started.
Download Laravel 5 Boilerplate according to the Quick Start Documentation. Also
git initfor the project.
Create a local MySQL database for development:
- Create a Procfile to teach Heroku how to boot up our app:
- Create a Heroku app. You will need the Heroku CLI installed.
- Add a PHP buildpack:
- Add MySQL to our Heroku project:
This creates a config variable called
CLEARDB_DATABASE_URL which you can view using the following command. Add CLEARDB_DATABASE_URL to our .env file.
Modify config/database.php so that we connect to our Heroku database.
- Set an app key:
- Load assets over HTTPS in production. Heroku uses
https://to host websites. If we try to load or files over
http://then we will get a Mixed Content, insecure stylesheet or insecure script error. Therefore, head into App/Providers/AppServiceProvider.php and configure to load everything over HTTPS in production:
- Push to Heroku.
Congrats! You’ve deployed your Laravel 5 application to the internet using Heroku.