6 Reasons to Move to Laravel Homestead

Note: to quickly get up and running with Homestead, see this quick tip. For an explanation on what it is, read below.

Laravel Homestead is, in a nutshell:

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.

In other words, it automatically does what we’ve done before manually through Vagrant and PuPHPet in articles like these.

So what makes it different from your run-of-the-mill Vaprobash/Vagrant/PuPHPet setup? Let’s see.

1. It Works

Unlike the other popular solutions out there for simplifying Vagrantfile setups, Homestead seldom fails to boot, and if it does, it’s fixed within minutes. If you’ve dealt with GUI Vagrant solutions, you’ve likely noticed how rare it is to get it all up and running after the very first vagrant up. It’s always something like an outdated or over-updated Puppet, out of date Ubuntu repos, or some other cryptic error that requires vigorous “foruming” to deconstruct. Homestead simply… works.

Homestead installs on Ubuntu 14.04. with PHP 5.5, so as new as it gets without diving into beta/RC territory, Nginx (because we’ve all given up on Apache by now, right?), MySQL and Postgres so you’re instantly ready for Heroku as well (their default is Heroku Postgres), Node (for all your static resource compilation needs, background tasks, and other less business critical things), Redis, Memcached and Beanstalkd (for all your caching and queueing needs), Laravel Envoy (for all your remote server task needs) and Fabric + Hipchat Extension so you can do application deployment through Hipchat (also known as chatops).

2. It’s Otwell Approved

Homestead being official, as in, made by Taylor Otwell, the father of Laravel, means it’s automatically assumed to hold to certain standards. While the Laravel community isn’t without its drama (who cares what a class is called? If a revolutionary new framework calls a model a potato, a facade, or a rocketship, it’s perfectly fine as long as the potato/facade/rocketship works), it’s the exclusivity of Taylor’s involvement with it that gives it a note of simplicity and quality that’s much needed in today’s PHP world. We’ve seen far too many open source projects ruined by team egos, zealous contributors, or incompetent jacks-of-all-trades and it’s my personal opinion that Taylor’s almost exclusive involvement in Laravel’s betterment is what makes it shine above the rest and truly allows it to compete with Phalcon in quality.

Homestead is his own project, termed the “official local development environment”, and he’ll do everything he can to keep it high quality and make sure it always works. Anything less, and it’s a smudge on his reputation. In PHP these days, there’s no better guarantee of a project’s long term reliability, than it being (mostly) owned by a person who cares that much about quality.

3. It’s Fast to Set Up

Setting Homestead up is a piece of cake. Following the instructions on the documentation page, all you need to do is add the homestead box to your Vagrant (if you don’t have it yet) and clone the repo.

There’s an extra step we’re not used to – setting up SSH. This is simple to do as well, and requires editing your Homestead.yaml file after cloning the repo. Just point the relevant lines to your SSH key(s) and you’re good to go. In my case, I had to change this:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1

authorize: /Users/me/.ssh/id_rsa.pub

keys:
    - /Users/me/.ssh/id_rsa

folders:
    - map: /Users/me/Code
      to: /home/vagrant/Code

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

variables:
    - key: APP_ENV
      value: local

to

---
ip: "192.168.10.10"
memory: 2048
cpus: 1

authorize: C:\Users\Bruno\.ssh\id_rsa.pub

keys:
    - C:\Users\Bruno\.ssh\id_rsa

folders:
    - map: D:\VM\vagrant_boxes\homestead\Homestead
      to: /home/vagrant/Code

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

variables:
    - key: APP_ENV
      value: local

After we run vagrant up, everything should fall into place:

As you can see, my procedure produced some errors, but it still ended up working just fine:

4. Ports

Homestead opens certain important ports by default which make maintaining and managing your database and other installed software on the VM from the host machine a breeze. For example, to connect to the installed MySQL database with MySQL Workbench installed on your host machine (in my case Windows), you just input the required credentials into the connection window:

The default MySQL and Postgres ports simply have a zero appended to them (i.e. 33060 for MySQL instead of 3306) which lets you connect to localhost (127.0.0.1:33060) and grants access to the DB on the VM.

The potential downside to this is the fact that you can’t have multple boxes running at the same time without changing ports due to conflicts. It would be better if the database connections were simply open, and one could connect to the IP of the VM as usual, but that’s easily fixed if need be – just see some of my previous vagrantfiles for what that looks like.

5. Best Practices and Common Ground

Due to Homestead being official, you can rest assured you’ll have a huge community available at all times for any assistance in the matter, should you encounter any problems. You’ll have the same starting point as everyone else using Homestead, and problems will automatically become much easier to diagnose.

6. Easy to add sites

Due to the simplicity of the configuration file one can tweak when fine tuning Homestead, adding new sites (vhosts) is a breeze – you don’t even have to deal with individual vhost configurations in nginx files.

By default, the Homestead.yaml file registers a single vhost called “homestead.app” and that one serves as the default site for the VM’s server configuration. You can access it directly by going to the IP of the VM in your browser, on the regular port 80: http://192.168.10.10. However, you might want to have additional applications or projects running and accessible name-wise through your host machine’s browsers. That’s where the “sites” block comes in. By defining another site like so:

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public
    - map: homestead2.app
      to: /home/vagrant/Code/H2/public  

you register a new vhost. Then, if you add that new site’s name to your hosts file (on any platform) you can access the new site by name through your browser, only you need to do so through port 8000 now: http://homestead2.app:8000.

This procedure allows you to add as many vhosts to your VM as you wish, serving multiple projects from a single box as needed.

Missing Features

Among some of the missing features, I’d name the following:

  • Homestead is missing a global composer installation, which means you have to obtain it manually for every project
  • The aforementioned ports issue – it would be better if ports were simply open, so one could connect to the IP of the VM, and not the localhost IP via a specific port. This would avoid port conflicts and would let one have multiple Homestead VMs running at the same time
  • There is no Laravel. Homestead would do well to include the basic Laravel project by default in the default vhost, so one can start developing instantly without having to create a new one from scratch
  • HHVM support would be neat, in the spirit of Vaprobash

Conclusion

Laravel Homestead is among the best and most stable PHP Vagrant environments yet. It’s extremely fast to boot, contains very few dependencies which can break during up time, and configures a modern, up to date PHP environment for one to immediately start hacking in.

Are you using it? Let us know.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • chipsn

    Settiing Environment Variables using did not work for me!

  • http://claudioludovico.panetta.it Claudio Ludovico Panetta

    The only problem with Homestead is the fact that I cannot, by default, set some different options. Fore example what if I want MariaDB instead of MySQL?

    • http://www.silentworks.co.uk Silent Works

      You do realize its just a Vagrant box right? there is absolutely nothing stopping your from adding your own packages to it.

    • http://www.bitfalls.com/ Bruno Skvorc

      You can re-provision it as usual, just add your own provision scripts into the Vagrantfile and install whatever you want.

      • http://claudioludovico.panetta.it Claudio Ludovico Panetta

        Thanks :D

  • http://michaelbrooks.co.uk/ Michael Brooks

    It’s great to see Taylor’s continued support and he’s the only developer who goes that extra mile in making it easier for his users to develop their projects within the localhost. It’ll be great to see what he does after making Homestead though as it seems impossible to keep coming up with innovative tools to help us. Soon the only thing he will be able to do is bug fixes plus support the latest version of PHP.

  • Paul

    “Nginx (because we’ve all given up on Apache by now, right?)”

    Seriously? There’s a lot of nonsense going around that Nginx whoops Apache, but how many actually compare a well-configured Apache2.4+PHP-FPM to a well-configured Nginx+PHP-FPM. The performance and memory usage differences are much smaller. Now Nginx for static content – yes that over Apache. Or how about Nginx at the front serving static content with Apache sitting behind?

    • Anónimo

      Apache is a great server, but nginx is the best:

      Performance of Apache 2.4 with the event MPM compared to Nginx. http://www.eschrade.com/page/performance-of-apache-2-4-with-the-event-mpm-compared-to-nginx/

      Nginx has replaced Apache as the most used web server among the top 10,000 sites. http://w3techs.com/technologies/cross/web_server/ranking

      • Paul

        You’ve misread the articles. As quoted from the first one:
        “for running PHP, Nginx was not faster than Apache. At first I figured that it would be and then it turned out not to be”

        And: “So it seems that if you are serving static content Nginx is still your best bet.”

        • http://www.bitfalls.com/ Bruno Skvorc

          My phrasing there was supposed to sound less serious than it did. Cheers for chiming in

  • amazzy

    For me, this defeats the whole purpose of vagrant! I use it to mirror my production environment- I’m not sure who the heck is using PHP 5.5, ubuntu 14.04, etc in a production environment (centos??)… I suppose it’s useful if you develop on windows, but who is actually doing any serious dev work and not on *nix?

    • http://www.bitfalls.com/ Bruno Skvorc

      I sometimes use Ubuntu 14.04 and PHP 5.5 in production, why not?

  • http://blog-unisys12.rhcloud.com/ Phillip Jackson

    Just started playing with Homestead today and found it quite nice. One of the really neat things that I noticed was when I created a project in a different directory as Homesteads root directory, it imports the outside project into Homestead for you. Neat, a little weird… call it what you want. But, if your thinking it is redundant, it is not. Why?

    Here is my quick example: (wish disqus supported Markdown!)

    folders:

    – map: /sites

    to: /home/vagrant/sites

    sites:

    – map: test.app

    to: /home/vagrant/sites/public

    Simple right? I am mapping the directory “C:/sites” to “/home/vagrant/sites”. This simply sets up the folder sharing and syncing. Then, to create the virtual host for that project, I map “test.app” to “/home/vagrant/sites”. Ok! Nothing special here! But, when you open your Homestead directory in Sublime, you will see the “sites” directory with your project files inside. Neat thing here… Open Windows Explorer and check the contents of the Homestead directory and you will not see the “sites” directory! You only see it in your editor. So, it is not redundant.

    Pretty slick! Now, you can either work out of a single directory (Homestead) or your individual directories.

    Also, I noticed that Homestead now has a global installation of Composer, which is nice. Mine was about a month out of date, so a simple “sudo composer self-update” solved that. There is a pull request https://github.com/laravel/homestead/pull/68 to make Composer update during provisions, so that would resolve this issue. Hey Taylor! Bump! Bump! :)

  • madmac10

    Holy sh*t! I called myself a Web Developer, but the industry must have passed me by while I was focused on marketing & social networks. Jeez–can anybody help me take the first steps needed toward understanding what most of this article is about?

    • http://www.bitfalls.com/ Bruno Skvorc

      Virtualbox allows you to run virtual machines on your host machine. Vagrant makes it easy to get small, development oriented, no-GUI virtual machine up and running on Virtualbox. Homestead is a preconfigured script for Vagrant, so that when you boot it up, you immediately have an up to date PHP + Ubuntu 14.04 environment up and running and are ready to work with the latest technologies.

      • madmac10

        Why is this an advantage over using the web server that comes with your OS of choice? Myself, I always set up AMP on my MacOS and never had a problem. I even preferred it over MAMP, but really, I fail to grok the advantages.

        • http://www.bitfalls.com/ Bruno Skvorc

          Because the one that comes with your OS is *always* outdated. Installing more software into your host machine increases bloat, slowing your host down over time. Also, all your apps share the same environment – when you have multiple clients, that’s rarely the case and you cannot maintain parity between production and development environments (maybe you installed the intl extension on your development machine, and one one production server, but the other production server for another clients doesn’t have it). Likewise, some clients may require different versions of PHP – you might end up in a legacy project that still uses the ancient PHP 5.4, and you started using 5.5 features inadvertently while coding up new features because you have 5.5 installed, and so on.

          Having a dedicated environment for each project which you can destroy and rebuild in a matter of minutes without having to reinstall anything at all is priceless and leads to stable design when dealing with large codebases, multiple projects and advanced features.

      • kenoli

        Thanks. It was not easy to find our what homestead and vagrant are via a web search. Every link seemed to assume I already knew.

        There seems to be a trend in articles to under-explain names and acronyms, as if there were an in-society that one could assume knows all the terminology, or maybe, i you do explain these things, it must mean you are not part of the in-crowd.

        Good communication that attempts to make things transparent to all is not a sign of ignorance, it is a sign of intelligence and compassion.

        Thanks,

        –Kenoli

  • Mohd. Mahabubul ALam

    La ravel Homestead is among the best and most stable PHP Vagrant
    environments yet. It’s extremely fast to boot, contains very few
    dependencies which can break during up time, and configures a modern, up
    to date PHP environment for one to immediately start hacking in.

  • Magbic

    @brunoskvorc:disqus is there an easy way or is it possible assign different ports to each site?

    :port 8888
    :port 431