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:
$ mysql -uroot -p
- Create a Procfile to teach Heroku how to boot up our app:
$ echo web: vendor/bin/heroku-php-apache2 public/ > Procfile
- Create a Heroku app. You will need the Heroku CLI installed.
heroku create YOUR_APP_NAME
- Add a PHP buildpack:
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-php
- Add MySQL to our Heroku project:
$ heroku addons:add cleardb
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.
$ heroku config | grep CLEARDB_DATABASE_URL
Modify config/database.php so that we connect to our Heroku database.
- Set an app key:
$ php artisan key:generate --show
- 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.
git add -A
Congrats! You’ve deployed your Laravel 5 application to the internet using Heroku.