Laravel Homestead

Introduction

Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.

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! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!

Homestead runs on any Windows, Mac, or Linux system, and includes Nginx, PHP, MySQL, PostgreSQL, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications.

Installation & Setup

First Steps

Before launching your Homestead environment, you must install VirtualBox 6.x, VMWare, Parallels or Hyper-V as well as Vagrant. All of these software packages provide easy-to-use visual installers for all popular operating systems.

To use the VMware provider, you will need to purchase both VMware Fusion / Workstation and the VMware Vagrant plug-in. Though it is not free, VMware can provide faster shared folder performance out of the box.

To use the Parallels provider, you will need to install Parallels Vagrant plug-in. It is free of charge.

Because of Vagrant limitations, The Hyper-V provider ignores all networking settings.

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 your terminal. It will take a few minutes to download the box, depending on your Internet connection speed:

          
            vagrant box add laravel/homestead
          
        

If this command fails, make sure your Vagrant installation is up to date.

Installing Homestead

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
          
        

You should check out a tagged version of Homestead since the master branch may not always be stable. You can find the latest stable version on the GitHub Release Page. Alternatively, you may checkout the release branch which always contains the latest stable release:

          
            cd ~/Homestead

            git checkout release
          
        

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:

        
          // Mac / Linux...
          bash init.sh

          // Windows...
          init.bat
        
      

Configuring Homestead

Setting Your Provider

The provider key in your Homestead.yaml file indicates which Vagrant provider should be used: virtualbox, vmware_fusion, vmware_workstation, parallels or hyperv. You may set this to the provider you prefer:

          
            provider: virtualbox
          
      
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:

          
            folders:
              - map: C:/xampp/htdocs
                to: /home/vagrant/xampp/htdocs
          
      
Configuring Nginx Sites

Not familiar with Nginx? No problem. 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:

          
            sites:
              - map: vuexyHTML.learn
                to: /home/vagrant/xampp/htdocs/vuesax-vuejs-admin-template/vuexy-html-laravel-template/public
              - map: vuexyHTMLStarter-Kit.learn
                to: /home/vagrant/xampp/htdocs/vuesax-vuejs-admin-template/vuexy-html-laravel-starter-kit/public
              - map: vuexyVuejs.learn
                to: /home/vagrant/xampp/htdocs/vuesax-vuejs-admin-template/vuexy-vuejs-laravel-template/public
              - map: vuexyVuejStarter-Kit.learn
                to: /home/vagrant/xampp/htdocs/vuesax-vuejs-admin-template/vuexy-vuejs-laravel-starter-kit/public
          
        

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.

Hostname Resolution

Homestead publishes hostnames over mDNS for automatic host resolution. If you set hostname: homestead in your Homestead.yaml file, the host will be available at homestead.local. MacOS, iOS, and Linux desktop distributions include mDNS support by default. Windows requires installing Bonjour Print Services for Windows.

Using automatic hostnames works best for "per project" installations of Homestead. 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. On Windows, it is located at C:\Windows\System32\drivers\etc\hosts. The lines you add to this file will look like the following:

          
            192.168.10.10 vuexyHTML.learn
            192.168.10.10 vuexyHTMLStarter-Kit.learn
            192.168.10.10 vuexyVuejs.learn
            192.168.10.10 vuexyVuejStarter-Kit.learn
          
        

Now you can simply run your homestead virtual host environment using below command.

        
cd laravel/homestead
vagrant up
vagrant ssh