Setting up a New Project Database in Homestead with Envoy

If you’ve just started using Laravel Homestead you know just how easy it makes getting started on a new project. On my first attempt I was up and running in under five minutes…very cool!

While adding a new project today I realized there isn’t a built-in way to do project-specific provisioning. There are a few tasks I do on nearly every project and I’d prefer to not have to jump into the VM to do them (mostly because I have to always look up the commands). Enter Envoy.

Nearly every site has a database. Why not automate its creation? Envoy can take care of that in a snap.


@servers(['vm' => '-p 2222 vagrant@'])

@task('init-local', ['on' => 'vm'])
    mysql -u homestead -psecret -e "create database :db_name


@servers(['vm' => '-p 2222 vagrant@'])

@task('init-local', ['on' => 'vm'])
    echo "*:*:*:*:secret" > ~/.pgpass
    chmod 600 ~/.pgpass
    createdb -h -U homestead -O homestead :db_name
    rm ~/.pgpass

This is just the beginning of what you could do for a new project within Homestead. Other obvious tasks might be migrating and seeding the database, running custom Artisan commands, or even other sync’d shell scripts. It’s a breeze!

  • Shame Envoy doesn’t work on Windows.

  • You could modify the @servers line to ‘vagrant@’ and then run the envoy command within your VM.

  • So @garrettstjohn:disqus – I can’t seem to get Envoy to connect. I have an Envoy.blade.php file in the root of my project and I have the following:

    Any ideas?


  • Are you getting any errors? Also, make sure your @task line is updated to reference the correct name (‘homestead’ instead of ‘vm’):

    @task(‘init-local’, [‘on’ => ‘homestead’])

  • I need to check for server errors. I actually set it up how you have it, but couldn’t get it to work, so I Googled “homestead and envoy laravel” and your blog was the second result. :) So no luck yet – let me dive deeper to see if I find errors – it is acting like it isn’t even connecting to the server though.