Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! That’s why I highly recommended this virtual environment setup.

Before launching your Homestead environment, you must download and install on your pc the ff:

  1. VirtualBox – an application that lets you run an operating system within your operating system. It keeps the data and activity of the operating system inside of it, which is called the guest operating system, separate from your regular operating system, which is called, the host operating system

Download virtual box here: https://www.virtualbox.org/wiki/Downloads

  1. Vagrant - tool for working with virtual environments, and in most circumstances, this means working with virtual machines. Vagrant provides a simple and easy to use command-line client for managing these environments, and an interpreter for the text-based definitions of what each environment looks like, called Vagrantfiles. Vagrant is open source, which means that anyone can download it, modify it, and share it freely.

Download vagrant here: http://www.vagrantup.com/downloads.html

  1. Homestead – Homestead is a vagrant package that provides a dev environment without the need to install PHP. To install homestead, you need to have a Git installed in your system. If none, download and install Git here: https://git-scm.com/downloads
  2. Composer - tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Download composer here: https://getcomposer.org/doc/00-intro.md

I like to put my Laravel project in this directory:

C:\Users\Dell

In your desired directory, execute the command below:

composer create-project --prefer-dist laravel/laravel Laravel

Now, we have a fresh laravel project in your local machine.

Alt Text

Run the below command thru git bash in your desired directory:

vagrant box add laravel/homestead

You will be prompted to select your choice for

  1. hyperv
  2. parallels
  3. virtualbox
  4. vmare_desktop

Alt Text

Choose number 3 then press enter.

Once laravel/homestead is added successfully for virtualbox, run this command:

git clone https://github.com/laravel/homestead.git Homestead
  • this will clone the homestead repository.

Then execute the ff:

bash init.sh
  • this will create the Homestead.yaml file.

Your Homestead.yaml file is inside your Homestead folder. Open it and configure accordingly.

Please see below configuration. I will explain it by section.

Alt Text

The above configuration is all about your IP address, cpus and provider of your VM. You can update it according to your desire but on my part, I’ll leave it as is.

Alt Text

If you are already working with git, you may have an SSH already. But if you don’t have, please run the command below:

ssh-keygen -t rsa -b 4096 -C your_email@example.com

This will create a ssh key for you and you don’t need to do anything else.

Alt Text

This is the part where we specify which folders in Windows should be synchronized with the virtual machine. In my case my map is: C:/Users/Dell/Laravel since my Laravel project is in that directory and I want it to mimic in /home/vagrant/Code directory in my virtual machine.

Alt Text

This section will let us map our domain to a folder in our VM. In my case I name my domain as homestead.test then map it to /home/vagrant/code/public in my virtual machine.

Alt Text

This is the summary of my Homestead.yaml

Alt Text

Don’t forget to edit your host file at: C:\Windows\System32\drivers\etc\hosts, then add this at the end of the file:

Alt Text

192.168.10.10 homestead.test

Go to your Homestead directory

cd Homestead

Then run this command:

vagrant up

This will create the environment. If the environment was already created and the up is just resuming a machine or booting it up.

Alt Text

Execute vagrant ssh:

Alt Text

Type cd Code then ll. The Laravel project that we have in our local machine is mimic in our vm.

Alt Text We can easily access our Laravel project via this address: http://homestead.test.

To shut down the vagrant machine, execute the ff:

vagrant halt

Note: if you change something on your Hometead.yaml, you need to run the command:

vagrant reload –provision
  • vagrant reload --provision will reboot the VM and run the provision steps.

Alt Text

My programming blog begins here, my Home - Laravel Homestead.