123
Laravel Forge: From Hello World to Hello Production https://joind.in/talk/42675 Joe Ferguson

Laravel Forge: Hello World to Hello Production

Embed Size (px)

Citation preview

Page 1: Laravel Forge: Hello World to Hello Production

Laravel Forge:From Hello World to

Hello Production

https://joind.in/talk/42675

Joe Ferguson

Page 2: Laravel Forge: Hello World to Hello Production

Who Am I?

Joe Ferguson

PHP Developer

Twitter: @JoePFerguson

Organizer of @MemphisPHP

@NomadPHP Lightning Talks

PHP FIG Secretary

Passionate about Community

Page 3: Laravel Forge: Hello World to Hello Production

Step One: Hello World

Page 4: Laravel Forge: Hello World to Hello Production

Create our projectVia Laravel Installer: laravel new hello-world

Via Composer: composer create-project laravel/laravel hello-world --prefer-dist

Page 5: Laravel Forge: Hello World to Hello Production

Where should our project live?

I prefer to keep things in ~/PhpstormProjects

Page 6: Laravel Forge: Hello World to Hello Production

Set up your dev environment

Page 7: Laravel Forge: Hello World to Hello Production

MAMP, LAMP, WAMP, WAT?

Mac/Linux/Windows Apache MySQL PHP

These are all great tools

Page 8: Laravel Forge: Hello World to Hello Production

Is your server running MAMP?

Page 9: Laravel Forge: Hello World to Hello Production

Why not develop ON the server?

Page 10: Laravel Forge: Hello World to Hello Production

Do not develop ON the server

Page 11: Laravel Forge: Hello World to Hello Production

Develop in the same environment

Page 12: Laravel Forge: Hello World to Hello Production

Servers are expensive*

* hardware is cheap, maintenance is expensive

Page 13: Laravel Forge: Hello World to Hello Production

Virtual Machines are cheap

Page 14: Laravel Forge: Hello World to Hello Production

Our Use Case:

Duplicate our server environment in a local virtual machine

Page 15: Laravel Forge: Hello World to Hello Production

Installing an OS takes time

Page 16: Laravel Forge: Hello World to Hello Production

Configuring your stack takes time

Page 17: Laravel Forge: Hello World to Hello Production

What if I told you…

There was a better way

Page 18: Laravel Forge: Hello World to Hello Production

Vagrant!

Page 19: Laravel Forge: Hello World to Hello Production

Vagrant allows you to:

•Create a server•Configure a server•Delete a server

…over and over and over..

Page 20: Laravel Forge: Hello World to Hello Production

Vagrant consumes the API of Virtualbox and other VM providers

Page 21: Laravel Forge: Hello World to Hello Production

Which Vagrant?

Page 22: Laravel Forge: Hello World to Hello Production

atlas.hashicorp.com

Page 23: Laravel Forge: Hello World to Hello Production

Laravel Homestead

“Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine.”

Page 24: Laravel Forge: Hello World to Hello Production

But I need…

Page 25: Laravel Forge: Hello World to Hello Production

What’s in the box:

•Ubuntu 14.04•PHP 5.6•HHVM•Nginx•MySQL & MariaDB•Postgres•Redis

•NodeJS•Bower•Grunt•Gulp•Beanstalkd•Memcached•Laravel Envoy

Fabric + HipChat Extension + more!

Page 26: Laravel Forge: Hello World to Hello Production

Getting Homestead

Install the box:vagrant box add laravel/homestead

Clone the Repository:git clone https://github.com/laravel/homestead.git Homestead

Page 27: Laravel Forge: Hello World to Hello Production

Configure Homestead

Default: Hello World:

Page 28: Laravel Forge: Hello World to Hello Production

Update /etc/hosts

192.168.10.10 hello-world.app

Page 29: Laravel Forge: Hello World to Hello Production

Ready to vagrant up

Our code will be shared from our host machine

And mapped to the vagrant machine

~/PhpstormProjects/hello-world

/home/vagrant/hello-world

Page 30: Laravel Forge: Hello World to Hello Production

How I use Homestead

Page 31: Laravel Forge: Hello World to Hello Production

Install Homestead

http://laravel.com/docs/5.1/homestead#per-project-installation

Page 32: Laravel Forge: Hello World to Hello Production

$ vagrant up

Page 33: Laravel Forge: Hello World to Hello Production

Why do I prefer per-project?

Page 34: Laravel Forge: Hello World to Hello Production

Sharing your Homestead environment

Do not version control:

Homestead.yml

DO version control:

Vagrantfile

after.sh

aliases

you should instruct potential collaborators to run the make command for themselves

Page 35: Laravel Forge: Hello World to Hello Production

What now?

Page 36: Laravel Forge: Hello World to Hello Production

How to access hello-world.app

These are ports forwarded to homestead

Page 37: Laravel Forge: Hello World to Hello Production

Connect to the Database

Page 38: Laravel Forge: Hello World to Hello Production

Connect via a browser

Page 39: Laravel Forge: Hello World to Hello Production

Connect via SSHYou could do this:

But this is easier:

Page 40: Laravel Forge: Hello World to Hello Production

Homestead is awesome!

We now have a local dev environment we can easily use, break, and restore

without having to reinstall the entire operating system and developer tools.

Break something?

Page 41: Laravel Forge: Hello World to Hello Production

Staking your own Homestead

I like to customize homestead AND

make sure I can easily update from upstream

Page 42: Laravel Forge: Hello World to Hello Production

Fork Homestead

Page 43: Laravel Forge: Hello World to Hello Production

Update your Homestead

Page 44: Laravel Forge: Hello World to Hello Production

Use after.sh for extras

./vendor/bin/homestead make —after

Page 45: Laravel Forge: Hello World to Hello Production

What could after.sh do?

Page 46: Laravel Forge: Hello World to Hello Production

You may not need after.sh

It is important to have a way to easily reproduce your development environment

so that those one off changes you make are documented and two months down the

road you don’t destroy & up your environment to find out you have stuff missing

Page 47: Laravel Forge: Hello World to Hello Production

Step ??? Go make something great

Page 48: Laravel Forge: Hello World to Hello Production

Tests!

You've written tests all along for your app right?

Page 49: Laravel Forge: Hello World to Hello Production

PHPUnit isn’t the only option!

•Behat•phpspec•Codeception

Page 50: Laravel Forge: Hello World to Hello Production

Codeception• Selenium WebDriver integration• Elements matched by name, CSS, XPath• Symfony2, Laravel4, Yii, Phalcon,• Zend Framework integration• PageObjects and StepObjects included• BDD-style readable tests• Powered by PHPUnit• API testing: REST,SOAP,XML-RPC• Facebook API testing• Data Cleanup• HTML, XML, TAP, JSON reports• CodeCoverage and Remote CodeCoverage• Parallel Execution

Page 51: Laravel Forge: Hello World to Hello Production

Codeception.com

Unit Testing

• Our methods work

Functional Testing• Our product works

Acceptance Testing

• Our product works as intended

Page 52: Laravel Forge: Hello World to Hello Production

PhantomJS

PhantomJS is a headless WebKit scriptable with a JavaScript API.

It has fast and native support for various web standards: DOM handling,

CSS selector, JSON, Canvas, and SVG.

Page 53: Laravel Forge: Hello World to Hello Production

Codeception + PhantomJS

Page 54: Laravel Forge: Hello World to Hello Production

Basic Acceptance Test

Page 55: Laravel Forge: Hello World to Hello Production

Automate our Testing

Page 56: Laravel Forge: Hello World to Hello Production

Travis-CI

•Great for OSS projects (And free!)•Easy to set up•Easily test multiple versions of PHP•Hosted on Travis Servers

Page 57: Laravel Forge: Hello World to Hello Production

.travis.yml

Page 58: Laravel Forge: Hello World to Hello Production

Jenkins CI

•Easy To Install•Easy Configuration•Multiple Languages•Probably Overkill for PHP•Hosted on your servers

Page 59: Laravel Forge: Hello World to Hello Production

TeamCity

•Easy To Install•Easy Configuration•Multiple Languages•Nice middle ground•Hosted on your servers

Page 60: Laravel Forge: Hello World to Hello Production

TeamCity

Page 61: Laravel Forge: Hello World to Hello Production

Build Config

Page 62: Laravel Forge: Hello World to Hello Production

Build Steps

Page 63: Laravel Forge: Hello World to Hello Production

Edit Build Step

Page 64: Laravel Forge: Hello World to Hello Production

Step Three: Hello Production

Page 65: Laravel Forge: Hello World to Hello Production

Traditional Deployment

Page 66: Laravel Forge: Hello World to Hello Production

Better Deployment

Page 67: Laravel Forge: Hello World to Hello Production

But you still have to…

•Update Dependencies•Run migrations•Update Assets

Page 68: Laravel Forge: Hello World to Hello Production

Continuous Delivery

Production can be updated anytime

Page 69: Laravel Forge: Hello World to Hello Production

Continuous Delivery VS

Continuous Deployment

Page 70: Laravel Forge: Hello World to Hello Production

Continuous Deployment

“Deploy my code every time tests pass”

Continuous Delivery

“We can deploy whenever we want…but we control when”

Magnus Hedemark: http://puppetlabs.com/blog/continuous-delivery-vs-continuous-deployment-whats-diff

Page 71: Laravel Forge: Hello World to Hello Production

Laravel Forge

“A simple way to deploy your Laravel applications onto blazing fast servers”

Page 72: Laravel Forge: Hello World to Hello Production

Forge is Homestead and more in the cloud

Page 73: Laravel Forge: Hello World to Hello Production

Forge is not a server host

Page 74: Laravel Forge: Hello World to Hello Production

Forge uses your servers

Page 75: Laravel Forge: Hello World to Hello Production

Forge uses any* server

*Any Internet accesible Ubuntu 14.04 x64 Server

Page 76: Laravel Forge: Hello World to Hello Production

Laravel Forge• Unlimited Servers.• Unlimited Sites.• Unlimited Deployments.• Push To Deploy.

Laravel Forge Plus• Share Servers With Teammates.• Unlimited Servers.• Unlimited Sites.• Unlimited Deployments.• Push To Deploy.

$10/Month$100/Year

$20/Month$140/Year

Page 77: Laravel Forge: Hello World to Hello Production

Adding Servers To Forge

Page 78: Laravel Forge: Hello World to Hello Production

Adding a site to a server

Page 79: Laravel Forge: Hello World to Hello Production

Adding a ssh key to a server

Page 80: Laravel Forge: Hello World to Hello Production

Adding scheduled (cron) jobs

Page 81: Laravel Forge: Hello World to Hello Production

Adding daemons (supervisor)

Page 82: Laravel Forge: Hello World to Hello Production

Creating server networks

Page 83: Laravel Forge: Hello World to Hello Production

Server Monitoring

Page 84: Laravel Forge: Hello World to Hello Production

Update Server Meta Data

Page 85: Laravel Forge: Hello World to Hello Production

Adding our hello-world site

Page 86: Laravel Forge: Hello World to Hello Production

Install our Git Repository

Page 87: Laravel Forge: Hello World to Hello Production

Configure App Deployment

Page 88: Laravel Forge: Hello World to Hello Production

Deploy!

Page 89: Laravel Forge: Hello World to Hello Production

Deploy!

Continuous Delivery!

Page 90: Laravel Forge: Hello World to Hello Production

Deployment Log

Page 91: Laravel Forge: Hello World to Hello Production

Setting Environment Variables

Page 92: Laravel Forge: Hello World to Hello Production

Queue Workers

Page 93: Laravel Forge: Hello World to Hello Production

Configure / Install SSL

Page 94: Laravel Forge: Hello World to Hello Production

LetsEncrypt.org100% Supported

Page 95: Laravel Forge: Hello World to Hello Production

Enable Quick Deploy

Page 96: Laravel Forge: Hello World to Hello Production

Quick Deploy Branch

Page 97: Laravel Forge: Hello World to Hello Production

Quick Deploy Branch

Continuous Deployment!

Page 98: Laravel Forge: Hello World to Hello Production

Recipes

Recipes a bash scripts that can be run on any of your Forge servers.

Page 99: Laravel Forge: Hello World to Hello Production

Cooking up Recipes

Think of recipes like our after.sh in Homestead

Page 100: Laravel Forge: Hello World to Hello Production

All the things!

Page 101: Laravel Forge: Hello World to Hello Production

Not All The Things

Some things we were doing in customize.sh we can do via Forge:

•Queue Workers•Cron Jobs

Page 102: Laravel Forge: Hello World to Hello Production

Create Recipe

Page 103: Laravel Forge: Hello World to Hello Production

Run Install Bower Recipe

Page 104: Laravel Forge: Hello World to Hello Production

Forge Emails You Recipe Report

Page 105: Laravel Forge: Hello World to Hello Production

HipChat Notifications

Page 106: Laravel Forge: Hello World to Hello Production

Slack Notifications

Page 107: Laravel Forge: Hello World to Hello Production

Restarting Services

Edit PHP Configuration

Page 108: Laravel Forge: Hello World to Hello Production

Delete the server

Page 109: Laravel Forge: Hello World to Hello Production

Deleting a site

Page 110: Laravel Forge: Hello World to Hello Production

Envoyer.io

Page 111: Laravel Forge: Hello World to Hello Production

Zero Downtime Deployments with

Envoyer.io

Page 112: Laravel Forge: Hello World to Hello Production

Envoyer10 Projects - $10/month or $100/year

20 Projects - $20/month or $200/year

Envoyer Plus

Unlimited Projects - $50/month or $500/year

Envoyer Premium

Page 113: Laravel Forge: Hello World to Hello Production

Add a project

Page 114: Laravel Forge: Hello World to Hello Production

Adding a Server

Page 115: Laravel Forge: Hello World to Hello Production

Add the SSH key from Envoyer

Page 116: Laravel Forge: Hello World to Hello Production

Test Connection Status

Envoyer now connected to our Forge Server

Page 117: Laravel Forge: Hello World to Hello Production

Project Path

Page 118: Laravel Forge: Hello World to Hello Production

Our first Deployment

Page 119: Laravel Forge: Hello World to Hello Production

Deployment Recap

Page 120: Laravel Forge: Hello World to Hello Production

Deploy when code is pushed

Page 121: Laravel Forge: Hello World to Hello Production

Free Video Series at Laracasts

https://laracasts.com/series/envoyer

https://envoyer.io/docs

Page 122: Laravel Forge: Hello World to Hello Production

Recap

Local Development: Use Homestead

Remote Deployment: Use Forge and Envoyer

Automate built tests and configure Continuous Deployment

Practice Continuous Delivery if not Continuous Deployment

Page 123: Laravel Forge: Hello World to Hello Production

Feedback!

Joe FergusonTwitter: @JoePFergusonEmail: [email protected]: joepferguson

Contact Info:

https://joind.in/talk/42675