Download pdf - Deploy Laravel on Heroku

Transcript
Page 1: Deploy Laravel on Heroku

Deploy Laravel on Heroku

Page 2: Deploy Laravel on Heroku

About Me

Eric Van Johnson PHP Developer, Architect and an Organizer of SDPHP

● Twitter: @shocm

● IRC: @shocm

Page 3: Deploy Laravel on Heroku

Laravel 101

We start with a standard Laravel deployment

And then a cd into our project directory

Page 4: Deploy Laravel on Heroku

Unlock you lock

We want to remove ‘composer.lock’ from

.gitignore

Page 5: Deploy Laravel on Heroku

Heroku Procfile

You can configure Heroku server by leveraging

a ‘Procfile’. We will use this to update our doc

root to point to our /public directory

Page 6: Deploy Laravel on Heroku

Git’er Done

Next we initiate our Git repo and commit

some changes.

Page 7: Deploy Laravel on Heroku

Use the --force

Your Laravel application will complain if it

doesn’t have a log file and it’s unable to

create one once deployed to Heroku. So we

will create it now and force add it to the repo

Page 8: Deploy Laravel on Heroku

Commit to your choices in life

Now we can do a git commit of our project.

Page 9: Deploy Laravel on Heroku

Heroku Time

You’ll need to have a Heroku account and have

the Heroku Toolbelt installed and configured.

Great place to get started:

https://devcenter.heroku.com/articles/getting-started-with-php#introduction

We’ll flash forward past this

Page 10: Deploy Laravel on Heroku

Spinning up Heroku

We create our Heroku instance and deploy our

repo to it.

Page 11: Deploy Laravel on Heroku

Check out your awesome app

At this time we

have our basic

Laravel

Application

deployed and

can view it.

Page 12: Deploy Laravel on Heroku

Add layers to the Application

Let’s update our routes, add a controller and add

a view like a normal application.

app/routes.php app/controllers/HelloController.php

app/views/hello/index.blade.php

Page 13: Deploy Laravel on Heroku

Check out your awesome app

Commit, push to

Heroku and go

to the new

route.

Page 14: Deploy Laravel on Heroku

Adding PostgreSQL to your app

Why PostgreSQL and not MySQL?

● Heroku doesn’t have ‘native’ MySQL support

● In Heroku world, PostgreSQL is a first class citizen.

● There is a solution that allows you to add a MySQL to your

Heroku app called ‘ClearDB’ addon if you really want it.

● Since we are using Laravel and Eloquent, we don’t actual

care what our datastore is.

Page 15: Deploy Laravel on Heroku

Adding PostgreSQL (Part 2)

Adding PostgreSQL is as simple as running a command.

Page 16: Deploy Laravel on Heroku

A peek at the config

Let’s see what was assigned to us

Page 17: Deploy Laravel on Heroku

Modify start.php

We are going to edit bootstrap/start.php to better detect

environments

Page 18: Deploy Laravel on Heroku

Create Heroku Configurations

Next we create configuration files specifically for Heroku at the

following path

Page 19: Deploy Laravel on Heroku

Configure Database

Also be sure to update

app/config/database.php and define

PostgeSQL

● 'default' => 'pgsql',

Commit and push

app/config/heroku/database.php

Page 20: Deploy Laravel on Heroku

Create APP_ENV Variable

Remember we are detecting which environment

we are in, in start.php using the variable

‘APP_ENV’. We will need to create and add that

variable to our Heroku environment.

Page 21: Deploy Laravel on Heroku

Create a migration

Now we create a migration using the normal

Laravel commands.

Commit and Push

Page 22: Deploy Laravel on Heroku

Run migration

After we push our new migration we need to run

the migration in the Heroku environment.

Page 23: Deploy Laravel on Heroku

Check migration was successful

Page 24: Deploy Laravel on Heroku

Enjoy Life

START CODING!