I’ve been hunting for an easy way to run multiple sites on a single vagrant box and kept coming up short. Maybe I’ve gotten rusty on my Googling skills but there was not much turning up for me. I could run several sites under VVV, but every time I’d spin up a fresh site something new would break.
It’s not the most straight-forward process but the community behind Bedrock and Trellis is pretty strong so I was able to track down a few posts about people attempting to achieve the same thing.
Individually both of these setups are pretty sweet, but Trellis also lets you easily manage development, staging and production environments.
Here’s how I managed to get it all setup and running for development on localhost.
Install Virtual Box and Vagrant
If you’ve already got the latest version of VirtualBox and Vagrant installed you can skip ahead to the next step.
If you’re not sure what version of Vagrant you have installed you can check with the following:
New to Vagrant? Check out Vagrant’s command-line documentation.
Install / Update Dependencies
Bedrock and Trellis have required dependencies that must be installed on your computer before installation can be successful.
First, be sure you have PHP 5.5 installed.
Also, check that you have Composer installed.
If you don’t yet have it, go ahead and install Composer.
This is the longer list, I hope you set aside a reasonable amount of time to get this up and running.
- Update or install Ansible
- If you already had VirtualBox installed, check you’re running version 4.3.10 or higher
- If you already had Vagrant installed, you’ll need version 1.5.4 or higher
- Update or install vagrant-bindfs — requires 0.3.1 or higher
- Install vagrant-hostsupdater
Boom, that was easy right? Let’s rock out with the next steps.
First, let’s create a directory where we want to run the whole shebang. I tucked my parent directory in the Documents folder of my computer.
Next, clone the Trellis repo into your new directory.
Hop into the Trellis directory and install the external Ansible roles/packages.
Time to get to installing Bedrock for each site we want to run on our Vagrant Box. First we need to return to the parent directory.
I’m now in the
fatpony directory I created. Next I’m going to clone Bedrock into my
fatpony directory and rename the
bedrock directory so I can easily identify which site it contains.
I’ve renamed my first Bedrock site directory
writingofriding and am going to repeat this process two more times so I’m running 3 sites on a single Vagrant Box. You can run more than 3 sites under a single Vagrant Box so if you need more just repeat as necessary.
You should now have a file structure that resembles the following –
fatpony/ - Primary folder for the project ├── trellis/ - Trellis ├── jobifarm/ - First bedrock-based site ├── horsepress/ - Second bedrock-based site └── writingofriding/ - Third bedrock-based site
Run Composer Inside Each Site
Let’s pop into each site directory and run composer. You can add dependencies before you run composer the first time to the
composer.json file in each site’s directory, or do it later and run
composer update from the command-line.
We don’t need to configure the
.env files for each site since these will be generated when we run
vagrant up the first time.
Trellis Development Setup
I’m only running through the development setup of Trellis in this article since your own needs will vary for staging and production. Head over to the Trellis documentation for help with staging and production setup.
trellis/group_vars/development/wordpress_sites.yml and you’ll be greeted with the following –
Keep in mind the default is to run a single site under Trellis, so we need to modify this file to setup not only our first site, but two more (or however many you decide to create).
I’ve copied lines 3-28 and pasted them at the bottom of the file twice so the file now contains structure for 3 sites. Next I’ve configured each site as I require. If you’re unsure how to configure each site checkout the Trellis documentation on configuring the
Save the file and we’re ready to run Vagrant! Make sure you’re inside the
trellis directory when you do this. We last left off inside one of the bedrock-based site directories so we need to move back into the main directory then into
/trellis/ before running
Load your new sites in the browser
Your sites are now ready to view in the browser, and to login and begin developing! Remember the wp/ url slug gives you access to the admin, so instead of
http://example.com/wp-login.php you’d have to navigate to