< go back to home

How To Setup Laravel Homestead

August 19, 2017

As the title says, this article is about setting up Homestead. First let us define what is Homestead. Laravel's site has a great definition of 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. " - Laravel Website

In fact, as with everything, Laravel has a great documentation on Homestead already which I encourage you to read. This article is to summarize that documentation to focus more on the actual commands. I will use this article as a reference for my other Laravel related tutorials so that a baseline clean environment is ensured.

Before proceeding, install the following tools that is needed to setup Homestead:

Make sure that you have proper SSH key if you still don't have one. This will be used to enter the virtual machine. In nix-based distro, you can generate keys as follows:

Download Vagrant Box for Homestead. This might take a while if this is the first time that the OS image, usually Ubuntu, has to be downloaded. It will be faster when using the box again as the image will be already in your machine.

Fetch and install the Homestead template codebase. It is recommended that it is placed in your home directory as it may host all your Laravel project.

Prepare the development folder that will contain your actual Laravel project. This is a separate folder from Homestead folder. You can create it anywhere.

Configure Homestead in the "Homestead.yaml" file which is in YAML format. For now, let's point to our laravel_projects folder. Update the "folders: to" and "sites: to" value for that. Open "Homestead.yaml" and replace the value of "folders":

We can access the site in browser using "homestead.app" because that is what we defined in "sites: map". You have to add this though in the hosts of your machine. In nix-based OS, open "/etc/hosts" and add the following line:

We are now ready to use Homestead. In the homestead folder, just run "vagrant up" to start he setup and "vagrant ssh" to enter the virtual machine. We'll also have to add the actual Laravel codebase but we can do that in the VM.

You may now check your browser in "homestead.app" and you should see Laravel's welcome message. Happy coding! :)

< go back to home