117
Laravel Forge: From Hello World to Hello Production https://joind.in/15530 Joe Ferguson

ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Embed Size (px)

Citation preview

Page 1: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Laravel Forge:From Hello World to Hello Production

https://joind.in/15530

Joe Ferguson

Page 2: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Who Am I?

Joe Ferguson

PHP Developer

Twitter: @JoePFerguson

Organizer of @MemphisPHP

@NomadPHP Lightning Talks

Passionate about Community

Page 3: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Step One: Hello World

Page 4: ZendCon 2015 - 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: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Where should our project live?

I prefer to keep things in ~/PhpstormProjects

Page 6: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

MAMP, LAMP, WAMP, WAT?

Mac/Linux/Windows Apache MySQL PHP

These are all great tools

Page 7: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Is your server running MAMP?

Page 8: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Why not develop ON the server?

Page 9: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Do not develop ON the server

Page 10: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Develop in the same environment

Page 11: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Servers are expensive

Page 12: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Virtual Machines are cheap

Page 13: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Our Use Case:Duplicate our server environment

in a local virtual machine

Page 14: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Installing an OS takes time

Page 15: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Vagrant!

Page 16: ZendCon 2015 - 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 17: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Which Vagrant?

Page 18: ZendCon 2015 - 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 19: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

But I need…

Page 20: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

What’s in the box:

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

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

Fabric + HipChat Extension + more!

Page 21: ZendCon 2015 - 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 22: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Configure HomesteadDefault: Hello World:

Page 23: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Update /etc/hosts192.168.10.10 hello-world.app

Page 24: ZendCon 2015 - 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 25: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

How I use Homestead

Page 26: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Install Homestead

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

Page 27: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

$ vagrant up

Page 28: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Why do I prefer per-project?

Page 29: ZendCon 2015 - 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 30: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

What now?

Page 31: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

How to access hello-world.app

These are ports forwarded to homestead

Page 32: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Connect to the Database

Page 33: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Connect via a browser

Page 34: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Connect via SSHYou could do this:

But this is easier:

Page 35: ZendCon 2015 - 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 36: ZendCon 2015 - 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 37: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Fork Homestead

Page 38: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Update your Homestead

Page 39: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Use after.sh for extras

./vendor/bin/homestead make —after

Page 40: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

What could after.sh do?

Page 41: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

You may not need after.shIt 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 42: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Step ??? Go make something great

Page 43: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Tests!

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

Page 44: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

PHPUnit isn’t the only option!

• Behat• phpspec• Codeception

Page 45: ZendCon 2015 - 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 46: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Codeception.com

Acceptance Testing

Functional Testing

Unit Testing

• Our methods work

• Our product works

• Our product works as intended

Page 47: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

PhantomJSPhantomJS 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 48: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Codeception + PhantomJS

Page 49: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Basic Acceptance Test

Page 50: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Automate our Testing

Page 51: ZendCon 2015 - 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 52: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

.travis.yml

Page 53: ZendCon 2015 - 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 54: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

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

Page 55: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

TeamCity

Page 56: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Build Config

Page 57: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Build Steps

Page 58: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Edit Build Step

Page 59: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Step Three: Hello Production

Page 60: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Traditional Deployment

Page 61: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Better Deployment

Page 62: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

But you still have to…

• Update Dependencies• Run migrations• Update Assets

Page 63: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Continuous Delivery

Production can be updated anytime

Page 64: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Continuous Delivery VS

Continuous Deployment

Page 65: ZendCon 2015 - 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 66: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Laravel Forge

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

Page 67: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Forge is Homestead and more in the cloud

Page 68: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Forge is not a server host

Page 69: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Forge uses your servers

Page 70: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Forge uses any* server

*Any Internet accesible Ubuntu 14.04 x64 Server

Page 71: ZendCon 2015 - 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 72: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding Servers To Forge

Page 73: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding a site to a server

Page 74: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding a ssh key to a server

Page 75: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding scheduled (cron) jobs

Page 76: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding daemons (supervisor)

Page 77: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Creating server networks

Page 78: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Server Monitoring

Page 79: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Update Server Meta Data

Page 80: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding our hello-world site

Page 81: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Install our Git Repository

Page 82: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Configure App Deployment

Page 83: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Deploy!

Page 84: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Deploy!

Continuous Delivery!

Page 85: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Deployment Log

Page 86: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Setting Environment Variables

Page 87: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Queue Workers

Page 88: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Configure / Install SSL

Page 89: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Enable Quick Deploy

Page 90: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Quick Deploy Branch

Page 91: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Quick Deploy Branch

Continuous Deployment!

Page 92: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Recipes

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

Page 93: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Cooking up Recipes

Think of recipes like our after.sh in Homestead

Page 94: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

All the things!

Page 95: ZendCon 2015 - 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 96: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Create Recipe

Page 97: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Run Install Bower Recipe

Page 98: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Forge Emails You Recipe Report

Page 99: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

HipChat Notifications

Page 100: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Slack Notifications

Page 101: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Restarting Services

Edit PHP Configuration

Page 102: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Delete the server

Page 103: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Deleting a site

Page 104: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Envoyer.io

Page 105: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Zero Downtime Deployments with

Envoyer.io

Page 106: ZendCon 2015 - 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 107: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Add a project

Page 108: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Adding a Server

Page 109: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Add the SSH key from Envoyer

Page 110: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Test Connection Status

Envoyer now connected to our Forge Server

Page 111: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Project Path

Page 112: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Our first Deployment

Page 113: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Deployment Recap

Page 114: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Deploy when code is pushed

Page 115: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Free Video Series at Laracasts

https://laracasts.com/series/envoyer

https://envoyer.io/docs

Page 116: ZendCon 2015 - 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 117: ZendCon 2015 - Laravel Forge: Hello World to Hello Production

Feedback!

https://joind.in/15530

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

Contact Info: