Spins up a dev environment using Ansible - ala DrupalVM. It will fire two VMs, an "app" server with nginx/php and a "db" server for the database. This is because we find the performance is significantly better with a pair of VMs.
Supported on all systems that natively support Vagrant, e.g. Windows, most main distributions of Linux and Apple's OSX.
All the following should be latest version possible on your system:
- Install Vagrant from https://www.vagrantup.com
- Install Virtualbox from https://www.virtualbox.org
- Install vagrant vbguest plugin:
vagrant plugin install vagrant-vbguest
- Install vagrant trigger plugin:
vagrant plugin install vagrant-triggers
Download and extract this template, rename it to match your project name and put it wherever you want it: GitHub generated zip
Then:
- Edit the "ce-vm/config.yml" file to meet your needs
- From within the "ce-vm" folder, use
vagrant up
to start and provision the VMs - Go make a cup of tea while Ansible does its thing
When you get back, you'll find a clean Drupal 8 installation waiting for you at:
There will be a new "www" folder next to "ce-vm" which contains your Drupal code.
You can then "hack" away at the Ansible playbooks at will. If you make changes,
just vagrant provision
in the "ce-vm" folder to apply them.
You can also open that "www" directory in your favourite IDE and hack away at Drupal!
If you want to keep up-to-date with the main playbooks, and not treat this as a pure fork, you can easily do so:
- Install vagrant triggers plugin:
vagrant plugin install vagrant-triggers
- Ensure "git" is accessible on your host computer.
You can then set the "ce_vm_upstream" flag to yes in your config.yml file. This will clone the base repo under ~./CodeEnigma, and use these playbooks before cloning the local ones.
This also means you can get rid of pretty much anything under the "ansible" folder for your project and only keep what you need to behave differently than the default.
Already have Drupal set up? No problem. Just rename the directory Drupal is in to "www" and move it within folder you extracted our Zip file to, so it sits alongside the "ce-vm" folder. Then your VMs will automatically mount and install your Drupal website.
If you're using another platform where the Drupal folder needs to be something else, such as "docroot", just change the "webroot" line in config.yml.
The installed Drupal will still be a clean install, so you'll need to seed
the database, and possibly the Drupal files directory too. The easiest way to
seed the database is to use drush
.
- On the server / computer where your work is,
drush sql-dump > backup.sql
- Copy "backup.sql" to your project folder
- Move to the "ce-vm" folder there in a terminal and
vagrant ssh
(log into the VM) - On your VM
cd /vagrant/www
(move to the Drupal folder) - Then
drush sql-cli < /vagrant/backup.sql
(restore the backup) - Finally
drush cc all
(clear the cache) - To leave the VM, type
exit
and press Enter
That's it! Your database is now seeded. The Stage File Proxy module for Drupal is the most efficient way to handle files, if you have a staging site somewhere online. It automatically connects Drupal to files on your stage site, so you don't need to manually place them on your local VM.
At Code Enigma we have a DNS entry that points dev.codeenigma.com to 192.168.56.2 so there is no need to mess with hosts files to use local development environments - anything.dev.codeenigma.com resolves to our local VMs.
There is an option to use NFS for mounting Drupal, instead of the inbuilt VirtualBox file system. It can be a tricky to set up, but it is a fair bit quicker. See comments in "ce-vm/config.yml" for details.
The next thing we'll be working on is Docker support. Vagrant natively wraps Docker, but we have focused on VirtualBox for a first release, because it is a more mature product and performs more consistently across all the target platforms.
After that, we're open to suggestion!