Why Laravel Homestead?
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/DownloadsVagrant - 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.htmlHomestead – 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:
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.
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
- hyperv
- parallels
- virtualbox
- vmare_desktop
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.
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 your_email@example.com
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
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.
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:
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.
My programming blog begins here, my Home - Laravel Homestead.
Please don't hesitate to leave a comment or ask any question to make this tutorial easily doable as possible to others.
Top comments (4)
How is your latency on Windows setup? No matter what conf I try I still got ~7sec load time when I reload the application in the browser. Sometimes managed to get ~2sec, but rather rare.
After some time of playing around I decided to switch to Ubuntu dev environment myself. The latest setup is having Ubuntu on my external SSD. Hook it up to any machine I have at hand, boot it up and continue where I left. Application load latency normal, like on a local dev environment :P
Still curious, how others are experiencing it on Windows and possibly go back some time.
Hi German,
Thanks for dropping by. Yours is quite fast. Actually in my case, it is way slower because of our internet speed here. I'm not sure if others are experiencing faster latency than yours. :)
I mean latency on the local dev environment, where you are not connected to the outside internet and just launch the application in the browser from your computer. I couldn't get it fast enough on Windows + virtualbox. Was wondering how does it work for you (or anybody who is setting this up on Windows).
ohh I see.. On my first launch on my app in the browser, it will take me like around 5 to 7sec. But on my next launch just around 2 sec.