Laravel 5 Step by Step Guide to Vagrant Homestead in Mac

Well, if you are looking for a step by step guide but just found the older one, you might be lucky because i have just setup mine with Vagrant Homestead which is most likely what you are looking for as well. In short, the one explain on their official website isn't very clear that i have to get out and read other article just to set this up. So for anyone convenient and for mine as well, i'll just quickly write down what i did and what makes it magically work in this step by step guide.

Install required scripts

Before you even decide to setup anything you will need to do install a number of scripts to help in setting up Homestead Vagrant.

Install Vagrant

First, go ahead and visit Vagrant official website and download the mac version of Vagrant and get it install on your machine Just click on the pkg and continue till the end and we are all good with Vagrant.

Now we know where this file is located, we just need to open up and starts configuring some important parts.

vi ~/.homestead/Homestead.yaml

i use vim, you can use nano and etc or whatever you like. And the most important parts are shown below,

// this is the public key
authorize: ~/.ssh/id_rsa.pub
// this is my private key that i normally use
keys:
- ~/.ssh/id_rsa
// in my macbook, i am playing all laravel files on ~/Vagrant/Code (i created it myself)
// and on Vagrant VM iw ill place it on /Users/claylua/Vagrant/Code
folders:
- map: ~/Vagrant/Code
to: /Users/claylua/Vagrant/Code
// i am mapping the Laravel files to claylua.com and on vagrant of vm, it will look for the
// directory located at /Users/claylua/Vagrant/Code/blog/public
sites:
- map: claylua.com
to: /Users/claylua/Vagrant/Code/blog/public
// i change the name of the database
databases:
- claylua

so edit your configuration file accordingly and to your liking and we can start creating Laravel base files.

Setup Laravel Base Files

As you can see on my Homestead.yaml file, i have tell the configuration to go to the directory ~/Vagrant/Code where i will setup Laravel there.

mkdir -p ~/Vagrant/Code

the above will create the folder needed.

cd ~/Vagrant/Code
laravel new blog

The above will create a new laravel blog folder.

Setup Vagrant

Now we have finish setup both laravel files and homestead configuration. It's time to start Vagrant and access our website via

Once this is done, do remember that i have setup 'claylua.com' to point to my laravel installation folder. Hence, i will need to setup this domain to point it to my local machine by doing this

sudo vi /etc/hosts

and add this line at the end

192.168.10.10 claylua.com

If you are wondering why its 192.168.10.10 its because on my homestead.yaml i have place it as this ip address. Once you've done that, all you need to do is to open up the url 'claylua.com' and you'll see the following display and if you don't like what you see. Just destory it via command line

homestead destroy

and if you find it too troublesome to hit one line then open up VirtualBox and 'stop and remove' it. And you can redo the `homestead up` again.

SSH into Vagrant VM

Since this is all VM, which is really another small machine on your physical machine, you can actually ssh into it and install any thing you want. By default you can ssh via

Adding New Sites

So you have nothing to do and wanted to add a new website to create new laravel project. Simply head over to the Homestead.yaml file and add it below,

// i am mapping the Laravel files to claylua.com and on vagrant of vm, it will look for the
// directory located at /Users/claylua/Vagrant/Code/blog/public
sites:
- map: claylua.com
to: /Users/claylua/Vagrant/Code/blog/public
// now i am adding a new website call shit
- map: shit.com
to: /Users/claylua/Vagrant/Code/shit/public

Similarly, i will need to add a new laravel folder into it

cd ~/Vagrant/Code
laravel new shit

Now i have to provision my server again and map the new locations from your Homestead directory.