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
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
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:
This will create a homestead.yaml file in ~/.homestead
To edit this file you can run:
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:
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:
Save and exist with ctrl + x and visit http://mysite.local
So ssh into your box run:
From here you can navigate to your site directory and install Laravel 4 as normal.
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.
To suspend your machine so you can re-use it you will need to exit homstead via:
to re-load, just run: