Laravel logo

There are a few tutorials around about using Laravel Homestead but none I could find with up-to-date instructions. So I have decided to make my own.

A great place to start is the official Laravel Homestead guideĀ http://laravel.com/docs/4.2/homestead

You will need to install Virtual Box and Vagrant. This is the base for your new environment.

CD into a directory where you would like to keep your projects. For me its one directory outside of my sites.

- USER
-- vagrant
--- projects
---- site 1
---- site 2

Install Homestead

Homestead is actually installed in~/.homestead and not in a visible directory.

In your terminal you will need to run:

composer global require "laravel/homestead=~2.0"

From here you will need to “place the ~/.composer/vendor/bin directory in your PATH so that homestead is executible”. To do this is actually very straight forward.

If your on a mac run:

sudo nano /etc/paths

This will open up your PATH’s file. You might already have a few things in here, just add ~/.composer/vendor/bin at the bottom and exit & save with ctrl + x

You will need to reload the PATH file so your changes can take affect.

Enter the following:

cd
. ./.profile echo $PATH

cd will take you back to your / directory and . ./.profile echo $PATH will refresh your PATH file.

You can now enter:

homestead init

This will create a homestead.yaml file in ~/.homestead

Edit YAML

To edit this file you can run:

homestead edit

The yaml file contains configuration data on your homestead sites.

You will need to set your SSH key. To do this run:

ssh-keygen -t rsa -C "USER@homestead"

where USER is your username

Once you have your key you will need to replace the section in the YAML file. You should have something like this.

authorize: /Users/USER/.ssh/id_rsa.pub

keys:
- /Users/USER/.ssh/id_rsa

Next we need to map our folders correctly. So given my projects are all sitting in Users/USER/vagrant/projects my folder YAML looks like:

folders:
- map: /Users/USER/vagrant/projects
to: /home/vagrant/projects

Where “vagrant/projects” are the same directories but referenced above differently.

Time to map our site.

For development I like to use .local as my TLD this way I don’t get confused, but its up to you what you choose.

In the YAML file under “sites:” change the name you would like to use as a reference and change the location of the public facing files.

sites:
- map: mysite.local
to: /home/vagrant/projects/mysite/html

Save your YAML file and run:

homestead up

This might take a little while to download all the components.

Once its done you can visit your site by going to the IP address from your YAML file “192.168.10.10”. If you don’t get any results make sure you have something in your html directory you defined earlier.

Update your hosts file

This will let you view your site at mysite.local

sudo nano /etc/hosts

Add the IP address “192.168.10.10” to the hosts file at the bottom. For example mine is:

192.168.10.10 mysite.local

Save and exist with ctrl + x and visit http://mysite.local

So ssh into your box run:

homestead ssh

From here you can navigate to your site directory and install Laravel 4 as normal.

Database

If your wondering about database connections you can use the following

Host: 127.0.0.1
User: homestead
Password: secret
Port: 33060

Personally I like to use Sequel Pro to view my databases on my Mac.

And that’s it, your done! Congratulations you have now installed Laravel Homestead.

Extra

To suspend your machine so you can re-use it you will need to exit homstead via:

exit

then run:

vagrant suspend

to re-load, just run:

vagrant up

References

http://laravel.com/docs/4.2/homestead

http://scotch.io/tutorials/php/getting-started-with-laravel-homestead



2 Comments

  1. Martyn

    I get this
    ./.profile: No such file or directory

    • Gerard Smith

      Hi Martyn,

      Did you include the extra period at the beginning? “. ./.profile” rather than “./.profile”


Leave a reply