Term of the week blog - local development environments

Zuzana K • February 3, 2020

laravel

There are different ways to run your Laravel project locally. In this article, I will cover three related terms that are mentioned in the official Laravel documentation: Vagrant, Homestead and Valet and my experiences with them.

Vagrant

Vagrant is a software used to manage and standardize development environments. It isolates dependencies and their configuration within a self-contained box. You can replicate someone else's environment configuration by using their Vagrantfile.

We have all been in a situation where something works on one computer but breaks on another. The reason for this could be different operating systems or a different setup or tools used by individual computers. It could be a number of things, and it can be quite hard to determine what exactly is the culprit. And even if you do, the chances are you set up your computer the way you like, so having to change our set up, install new tools or programmes just to run a project is not ideal.

This is where using a virtual development environment shines.

If you want to share your project with someone else, create a Vagrantfile and share it with other developers. Vagrantfile is used to describe the type of machine and the configuration needed for the specific project and should be part of the project's files committed to version control. This is why, when someone else forks your project, they get the Vagrantfile with the rest of the codebase and, provided they have Vagrant installed on their machine, all they need to do is vagrant up, and all dependencies are installed in their Vagrant box, ready to be used.

Installing Vagrant is quite straightforward.

Just head over to Download Vagrant page and select the package for your operating system. Once the package downloads, install it via the provided installer. You will also need to install either VirtualBox, VMWare, Parallels or Hyper-V.

If everything goes well, you'll be able to type the vagrant command in your terminal and get a list of available commands.

Having Vagrant and VirtualBox installed means you can go ahead and install Laravel Homestead.

Links

Vagrant official docs
ShellHacks - Vagrant tutorial for beginners - In 5 Minutes
Quentin Watt YouTube tutorials

Homestead

Laravel Homestead is an official, pre-set Vagrant box. It makes it very simple to serve Laravel applications. It comes with everything you could possibly need to develop your Laravel application: PHP, Ngnix, MySQL, PostgreSQL, Redis, Memcached, Node, and others. And if something goes wrong, you can destroy your Homestead in minutes and start over!

Homestead is very closely related to Vagrant, because it is a Vagrant box specifically developed for Laravel applications. It comes with everything a standard Laravel app needs - and more!

A significant benefit of Homestead is that it will run on any operating system: Linux, Windows or macOS. This is important because the other popular Laravel development environment, Laravel Valet, currently only runs on macOS. More about Valet below.

I have followed Quentin Watt's YouTube tutorial, and got almost to the end, but had an issue somewhere which meant that when I ssh into my Virtual Machine (which was running just fine), I did not see any code directory there. I rewatched the relevant part of the tutorial a few times, checked the Homestead.yaml file over and over again, but then decided to move on.

Homestead is a great option to serve your Laravel sites, but it was too complicated for my own needs.

I might re-visit this again in the future and try to install Laravel Homestead again, but for now, I will carry on using Laravel Valet.

Links

Offical Homestead docs
Dan Walker's tutorial
Quentin Watt YouTube tutorials

Valet

Valet is a Laravel environment for Mac minimalists. It offers an easy and convenient way to run Laravel projects locally. It requires manual installation of PHP and MySQL, but only a minimal configuration. Once installed, Valet can be parked in a directory of your choice, and Valet will serve all projects in this directory. You can use Valet to serve other frameworks and content management systems too, including WordPress, Symphony, Statamic and many others.

Valet is the last term I am going to talk about today. Similarly to Homestead, Valet is another Laravel development environment. Unlike Homestead, Valet was originally only meant to work on macOS. However, there is a way to make Valet work on Windows using Cretu Eusebiu's package.

The main difference between Valet and Homestead is that while Homestead comes with everything you might need in your Laravel project, Valet is very minimalistic. You will even need to install PHP and MySQL manually if you don't already have these.

However, Valet is said to be much faster than Homestead. It is easier to set up and once set up you can pretty much forget about it - it just works. You can park in it any of your directories (I parked Valet in a directory called ~/Sites, you can even park it in multiple directories (I have it also parked in ~/Projects/Sites)). You can link an individual project to Valet, no matter where this project lives (valet link in the project root).

You can change the top-level domain name from .test to .whatever by running valet tld whatever command in the terminal.

You can even secure your sites over encrypted TLS using HTTP/2 by running valet secure blog in your terminal (where blog is your project name/directory). To unsecure it, run valet unsecure blog.

It's that easy.

There are many more commands that I haven't mentioned here, and I am not using yet because I am discovering them as and when needed.

I have been using Valet for a while now, I used it on my Windows machine as well as my Mac. Given my recent experience with Homestead, I am even more grateful for its simplicity and ease of use, and I would definitely recommend it to others!

Links

Hashvel tutorial - How to install Laravel Valet on Windows
Cretu Eusebiu - Valet for Windows package
Comparison between Valet and Homestead

Would you like to comment or connect? I'm on Twitter!