21
Chapter 2 Laravel Homestead

Ch2 Laravel Homestead 060915

Embed Size (px)

DESCRIPTION

mm

Citation preview

Page 1: Ch2 Laravel Homestead 060915

Chapter 2 Laravel Homestead

Page 2: Ch2 Laravel Homestead 060915

Outlines

• Introduction

• Installation & Setup

• Configuring Homestead

• Launching The Vagrant Box

• Daily Usage

• Blackfire Profiler

Page 3: Ch2 Laravel Homestead 060915

Introduction (1)

• Vagrant provides a simple, elegant way to manage and provision Virtual Machines

• Laravel Homestead is an official, pre-packaged Vagrant “box” – It have pre-install PHP, HHVM, a web server, and any

other server software

• Homestead runs on any OS: Windows, Mac, or Linux

Page 4: Ch2 Laravel Homestead 060915

Introduction (2)

• There are predefined components that included within Laravel Homestead– Ubuntu 14.04

– PHP 5.6

– HHVM

– Nginx

– MySQL

– Postgres

– Node (With PM2, Bower, Grunt, and Gulp)

– Redis– Memcached– Beanstalkd– Laravel Envoy– Blackfire Profiler

Page 5: Ch2 Laravel Homestead 060915

Installation & Setup

• Install VirtualBox or VMWare first as well as Vagrant– All of these software packages provide easy-to-use visual

installers for all popular operating systems

• To use the VMware provider, you will need to purchase both VMware Fusion/Desktop and the VMware Vagrant plug-in

Page 6: Ch2 Laravel Homestead 060915

Installing The Homestead Vagrant Box

• Add the laravel/homestead box to Vagrant installation using the following command – vagrant box add laravel/homestead

• If this command fails, use the following command:– vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead

Page 7: Ch2 Laravel Homestead 060915

Cloning The Homestead Repository

• You may install Homestead by simply cloning the repository

• Consider cloning the repository into a Homestead folder within your “home” directory

• After that, run the following command from the Homestead directory to create the Homestead.yaml configuration file:– bash init.sh

Page 8: Ch2 Laravel Homestead 060915

Configuring Homestead

• There are some tasks that should be performed to configure Homestead– Setting Your Provider

– Setting Your SSH Key

– Configuring Shared Folders

– Configuring Nginx Sites

– The Hosts File

Page 9: Ch2 Laravel Homestead 060915

Setting Your Provider

• The provider key in your Homestead.yaml file indicates which Vagrant provider should be used– virtualbox

– vmware_fusion

Page 10: Ch2 Laravel Homestead 060915

Setting Your SSH Key

• You should also configure the path to your public SSH key

• You can generally create an SSH key pair using the following command:– ssh-keygen -t rsa -C "you@homestead"

Page 11: Ch2 Laravel Homestead 060915

Configuring Shared Folders

• The folders property of the Homestead.yaml file lists all of the folders you wish to share

• They will be kept in sync between your local machine and the Homestead environment

• You may configure as many shared folders as necessary:– folders:

– - map: ~/Code

– to: /home/vagrant/Code

Page 12: Ch2 Laravel Homestead 060915

Configuring Nginx Sites

• The sites property allows you to easily map a “domain” to a folder on your Homestead environment

• A sample site configuration is included in the Homestead.yaml file

• You may add as many sites to your Homestead environment as necessary

Page 13: Ch2 Laravel Homestead 060915

The Hosts File

• Adds the “domains” for your Nginx sites to the hosts file

• The hosts file will redirect your requests for the local domains into your Homestead environment– On Mac and Linux, this file is located at /etc/hosts

– On Windows, it is located at C:\Windows\System32\drivers\etc\hosts

– Make sure the IP address listed is the one you set in your Homestead.yaml file

Page 14: Ch2 Laravel Homestead 060915

Launching The Vagrant Box

• Once you have edited the Homestead.yaml to your liking, run the vagrant up command from your Homestead directory– Vagrant will boot the virtual machine and automatically

configure your shared folders and Nginx sites automatically

• To destroy the machine, you may use the vagrant destroy --force command.

Page 15: Ch2 Laravel Homestead 060915

Per Project Installation

• You may instead configure a Homestead instance for each specific project

• Installing Homestead per project may be beneficial if you wish to ship a Vagrantfile directly within your project

• To install Homestead directly into your project, require it using Composer:

composer require laravel/homestead

Page 16: Ch2 Laravel Homestead 060915

Daily Usage (1)

• Connecting Via SSH– You can SSH into your virtual machine by issuing the

vagrant ssh terminal command from your Homestead directory

– But, since you will probably need to SSH into your Homestead machine frequently, consider creating an “alias” on your host machine to quickly SSH into the Homestead box

– You can simply use the “vm” command to SSH into your Homestead machine from anywhere

Page 17: Ch2 Laravel Homestead 060915

Daily Usage (2)

• Connecting To Databases– A homestead database is configured for both MySQL and

Postgres out of the box– Laravel’s local database configuration is already set to use this

database by default– To connect to your MySQL or Postgres database, you should

connect to 127.0.0.1 and port 33060 (MySQL) or 54320 (Postgres)

Page 18: Ch2 Laravel Homestead 060915

Daily Usage (3)

• Adding Additional Sites– To add an additional site, add the site to your Homestead.yaml file and then run the vagrant provision terminal command

Page 19: Ch2 Laravel Homestead 060915

Ports

• SSH: 2222! Forwards To 22

• HTTP: 8000 ! Forwards To 80

• HTTPS: 44300! Forwards To 443

• MySQL: 33060! Forwards To 3306

• Postgres: 54320 !Forwards To 5432

Page 20: Ch2 Laravel Homestead 060915

Blackfire Profiler

• Blackfire Profiler by SensioLabs automatically gathers data about your code’s execution, such as RAM, CPU time, and disk I/O

• Homestead makes it a breeze to use this profiler for your own applications– All of the proper packages have already been installed on

your Homestead box, you simply need to set a Blackfire Server ID and token in your Homestead.yaml file

Page 21: Ch2 Laravel Homestead 060915

Installation Recap

• Understanding?

• Implementation?