You are on page 1of 21

Chapter 2

Laravel Homestead

Outlines

Introduction
Installation & Setup
Configuring Homestead
Launching The Vagrant Box
Daily Usage
Blackfire Profiler

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

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

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

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/homes
tead

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

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

Setting Your Provider


The provider key in your Homestead.yaml
indicates which Vagrant provider should be used
virtualbox
vmware_fusion

file

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"

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

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

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

Launching The Vagrant Box


Once you have edited the Homestead.yaml to your
liking, run the vagrant
Homestead directory

up

command

from

your

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.

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

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

Daily Usage (2)


Connecting To Databases
A homestead database is configured for both MySQL and
Postgres out of the box
Laravels 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)

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

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

Blackfire Profiler
Blackfire Profiler by SensioLabs automatically gathers

data about your codes 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

Installation Recap

Understanding?
Implementation?

You might also like