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:
- 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
- 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
- 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
- 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:
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.
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
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:
- 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.
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.
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 firstname.lastname@example.org
This will create a ssh key for you and you don’t need to do anything else.
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.
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.
This is the summary of my Homestead.yaml
Don’t forget to edit your host file at: C:\Windows\System32\drivers\etc\hosts, then add this at the end of the file:
Go to your Homestead directory
Then run this command:
This will create the environment. If the environment was already created and the up is just resuming a machine or booting it up.
Execute vagrant ssh:
Type cd Code then ll. The Laravel project that we have in our local machine is mimic in our vm.
We can easily access our Laravel project via this address: http://homestead.test.
To shut down the vagrant machine, execute the ff:
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.
My programming blog begins here, my Home - Laravel Homestead.