126
Laravel 5.1: From Homestead to the Cloud https://joind.in/14758 Joe Ferguson

php[world] 2015 Laravel 5.1: From Homestead to the Cloud

Embed Size (px)

Citation preview

Laravel 5.1:From Homestead to the Cloud

https://joind.in/14758

Joe Ferguson

Who Am I?

Joe Ferguson

PHP Developer

Twitter: @JoePFerguson

Organizer of @MemphisPHP

@NomadPHP Lightning Talks

Passionate about Community

Laravel 5.1 What’s New?

PHP 5.5.9+

Laravel 5.1 will receive bug fixes for 2 years and security fixes for 3 years

PSR-2

Event Broadcasting

Middleware Parameters

Testing Overhaul

Encryption

How to get from Homestead to the Cloud

Step One: Hello World

Create our projectVia Laravel Installer: laravel new hello-world

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

Where should our project live?

I prefer to keep things in ~/PhpstormProjects

MAMP, LAMP, WAMP, WAT?

Mac/Linux/Windows Apache MySQL PHP

These are all great tools

Is your server running MAMP?

Why not develop ON the server?

Do not develop ON the server

Develop in the same environment

Servers are expensive

well, they used to be…

Virtual Machines are cheap

Our Use Case:Duplicate our server environment

in a local virtual machine

Installing an OS takes time

Vagrant!

Vagrant allows you to:• Create a server• Configure a server• Delete a server

…over and over and over..

Which Vagrant?

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.”

But I need…

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!

Getting Homestead

Install the box:vagrant box add laravel/homestead

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

Configure HomesteadDefault: Hello World:

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

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

How I use Homestead

Install Homestead

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

$ vagrant up

Why do I prefer per-project?

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

What now?

How to access hello-world.app

These are ports forwarded to homestead

Connect to the Database

Connect via a browser

Connect via SSHYou could do this:

But this is easier:

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?

Staking your own Homestead

I like to customize homestead AND

make sure I can easily update from upstream

Fork Homestead

Update your Homestead

Use after.sh for extras

./vendor/bin/homestead make —after

What could after.sh do?

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

Step ??? Go make something great

Tests!

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

PHPUnit isn’t the only option!

• Behat• phpspec• Codeception

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

Codeception.com

Acceptance Testing

Functional Testing

Unit Testing

• Our methods work

• Our product works

• Our product works as intended

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.

Codeception + PhantomJS

Basic Acceptance Test

Automate our Testing

Travis-CI

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

.travis.yml

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

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

TeamCity

Build Config

Build Steps

Edit Build Step

Step Three: Hello Production

Traditional Deployment

Better Deployment

But you still have to…

• Update Dependencies• Run migrations• Update Assets

Continuous Delivery

Production can be updated anytime

Continuous Delivery VS

Continuous Deployment

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

Laravel Forge

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

Forge is Homestead and more in the cloud

Forge is not a server host

Forge uses your servers

Forge uses any* server

*Any Internet accesible Ubuntu 14.04 x64 Server

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

Adding Servers To Forge

Adding a site to a server

Adding a ssh key to a server

Adding scheduled (cron) jobs

Adding daemons (supervisor)

Creating server networks

Server Monitoring

Update Server Meta Data

Adding our hello-world site

Install our Git Repository

Configure App Deployment

Deploy!

Deploy!

Continuous Delivery!

Deployment Log

Setting Environment Variables

Queue Workers

Configure / Install SSL

Enable Quick Deploy

Quick Deploy Branch

Quick Deploy Branch

Continuous Deployment!

Recipes

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

Cooking up Recipes

Think of recipes like our after.sh in Homestead

All the things!

Not All The Things

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

• Queue Workers• Cron Jobs

Create Recipe

Run Install Bower Recipe

Forge Emails You Recipe Report

HipChat Notifications

Slack Notifications

Restarting Services

Edit PHP Configuration

Delete the server

Deleting a site

Envoyer.io

Zero Downtime Deployments with

Envoyer.io

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

Add a project

Adding a Server

Add the SSH key from Envoyer

Test Connection Status

Envoyer now connected to our Forge Server

Project Path

Our first Deployment

Deployment Recap

Deploy when code is pushed

Free Video Series at Laracasts

https://laracasts.com/series/envoyer

https://envoyer.io/docs

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

Feedback!

https://joind.in/14758

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

Contact Info: