Homestead is a virtual development environment for Laravel. It’s supper easy to install and use on your machine. Before using Laravel Homestead, you have VirtualBox and Vagrant installed on your machine.
First, you have to install VirtualBox package, which is available in the ubuntu’s repositories. You may use the terminal command to install it on your computer.
sudo apt install virtualbox
After installed the VirtualBox, you may need to install the Vagrant to your computer. Use bellow the command for it:
sudo apt install vagrant
If you will get any problem to installed current version of Vagrant above that command, you may download the Vagrant package using the curl command:
curl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb
Once the .deb file is downloaded, install it by using this command:
sudo apt install ./vagrant_2.2.9_x86_64.deb
After installed, you may check the version of Vagrant by using this command:
Once, VirtualBox and Vagrant installed, you should add the laravel/homestead box to your vagrant installation using the command. It will take a few minutes to download the box.
vagrant box add laravel/homestead
Now, you may install Homestead by cloning the repository onto your host machine. 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 directory:
Configuring Shared Folders
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:
Configuring Nginx Sites
The sites property allows you to easily map a "domain" to a folder on your Homestead environment. A sample site configuration is included in the Homestead.yaml file. Again, you may add as many sites to your Homestead environment as necessary. Homestead can serve as a convenient, virtualized environment for every Laravel project you are working on:
- map: project1.test
If you change the sites property after provisioning the Homestead box, you should re-run vagrant reload --provision to update the Nginx configuration on the virtual machine.
If you host multiple sites on a single Homestead instance, you may add the "domains" for your web 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.
Open ubuntu hosts file by using this command:
sudo nano /etc/hosts
And add your domain name on this hosts file. This domain name should be similar with sites property in your Homestead.yaml file.
Make sure the IP address listed is the one set in your Homestead.yaml file. Once you have added the domain to your hosts file and launched the Vagrant box you will be able to access the site via your web browser:
Once you have edited the Homestead.yaml to your liking, run the vagrant up command from your Homestead directory. Vagrant will boot the virtual machine and automatically configure your shared folders and Nginx sites.