Laravel Homestead strives to make the entire Laravel development experience delightful. Working with Vagrant, Laravel Homestead provides a simple, elegant way to manage your local development environment and provision Virtual Machines on your local machine.
We will show you how to setup Laravel Homestead in this page, to get more information, please refer to:https://www.laravel.com/docs/5.2/homestead
We will use Git Bash as command-line tool, also Laravel will use GIT as recommended version control system, so try to install Git as your first step.
Virtual Box and Vagrant
Before launching your Homestead environment, you must install VirtualBox 5.x or VMWare as well as Vagrant. In this demo, we are using Virtual Box 5.x. All of these software packages provide easy-to-use visual installers for all popular operating systems. So go ahead to download Virtual Box 5.x and Vagrant on your local machine.
Installing The Homestead Vagrant Box
Once VirtualBox / VMware and Vagrant have been installed, you should add the laravel/homestead box to your Vagrant installation using the following command in Git Bash
vagrant box add laravel/homestead
It may take a while to download the package, depends on your internet connection. I failed once, but it can resume the download from last drop point. I am successful on the second try.
You may install Homestead by simply cloning the repository. Consider cloning the repository into a Homestead folder within your “home” directory, as the Homestead box will serve as the host to all of your Laravel projects:
git clone https://github.com/laravel/homestead.git Homestead
Once you have cloned the Homestead repository, run the bash init.sh command from the Homestead directory to create the Homestead.yaml configuration file. The Homestead.yaml file will be placed in the ~/.homestead hidden directory:
After initiate homestead, the system will create its configure file in your ~/.homestead/Homestead.yaml file.
The provider key in Homestead.yaml file indicates which Vagrant provider should be used: virtualbox, vmware_fusion, or vmware_workstation. You may set this to the provider you prefer:
The folders property of the Homestead.yaml file lists all of the folders you wish to share with your Homestead environment. As files within these folders are changed, they will be kept in sync between your local machine and the Homestead environment. You may configure as many shared folders as necessary:
folders: - map: ~/Code to: /home/vagrant/Code
In windows, we need provide full path:
folders: - map: c:/Users/Qiang/Code to: /home/vagrant/Code
The sites property allows you to easily map a “domain” to a folder on your Homestead environment.
sites: - map: matrix5.app to: /home/vagrant/Code/Matrix5/public
Set Your SSH Key
you can configure the path to your public SSH key, as well as the folders you wish to be shared between your main machine and the Homestead virtual machine.
Don’t have an SSH key? On Mac and Linux, you can generally create an SSH key pair using the following command:
ssh-keygen -t rsa -C "you@homestead"
On Windows, you may install Git and use the Git Bash shell included with Git to issue the command above.
Once you have created a SSH key, specify the key’s path in the authorize property of your Homestead.yaml file.
The whole Homestead.yaml file should look like:
By defining another site like so:
sites: - map: matrix5.app to: /home/vagrant/Code/Matrix5/public - map: dev.matrix5.app to: /home/vagrant/Code/Matrix5dev/public
The Hosts File
You must add the “domains” for your Nginx sites to the hosts file on your machine. The hosts file will redirect requests for your Homestead sites into your Homestead machine. On Mac and Linux, this file is located at /etc/hosts. On Windows, it is located at C:\Windows\System32\drivers\etc\hosts. The lines you add to this file will look like the following:
Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.
You may install Laravel by issuing the Composer create-project command in your terminal:
composer create-project --prefer-dist laravel/laravel Matrix5
Because Installed Composer before, so it will warning to up-to-date
Running Composer self-update:
Then install Laravel:
Because Laravel is one project from Symfony, so you will get a lot of Symfony warning, you don’t have to install all these package or library if you don’t need them, so just ignore these warnings.
Launching The Vagrant Box
Now, you are ready to launching the virtual machine on your local. run the vagrant up command from your Homestead directory. Vagrant will boot the virtual machine and automatically configure your shared folders and Nginx sites.
To destroy the machine, you may use the vagrant destroy –force command.
You also can use Virtual Box app to check your Laravel Homestead status.
Now you can access the site via your web browser: