Deploy Laravel on Heroku

Post on 15-Jul-2015

554 views 4 download

Transcript of Deploy Laravel on Heroku

Deploy Laravel on Heroku

About Me

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

● Twitter: @shocm

● IRC: @shocm

Laravel 101

We start with a standard Laravel deployment

And then a cd into our project directory

Unlock you lock

We want to remove ‘composer.lock’ from

.gitignore

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

Git’er Done

Next we initiate our Git repo and commit

some changes.

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

Commit to your choices in life

Now we can do a git commit of our project.

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

Spinning up Heroku

We create our Heroku instance and deploy our

repo to it.

Check out your awesome app

At this time we

have our basic

Laravel

Application

deployed and

can view it.

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

Check out your awesome app

Commit, push to

Heroku and go

to the new

route.

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.

Adding PostgreSQL (Part 2)

Adding PostgreSQL is as simple as running a command.

A peek at the config

Let’s see what was assigned to us

Modify start.php

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

environments

Create Heroku Configurations

Next we create configuration files specifically for Heroku at the

following path

Configure Database

Also be sure to update

app/config/database.php and define

PostgeSQL

● 'default' => 'pgsql',

Commit and push

app/config/heroku/database.php

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.

Create a migration

Now we create a migration using the normal

Laravel commands.

Commit and Push

Run migration

After we push our new migration we need to run

the migration in the Heroku environment.

Check migration was successful

Enjoy Life

START CODING!