The basic tools needed to install this box are:
- Vagrant - https://www.vagrantup.com/downloads.html
- VirtualBox - https://www.virtualbox.org/wiki/Downloads
- Ansible - https://valdhaus.co/writings/ansible-mac-osx
- Drush - http://docs.drush.org/en/master/install-alternative
- Create a fork in the %project_name% Repo and clone the site to your ~/Sites folder:
git clone %project_origin_repo% ~/Sites/%production_url%
- CD into your site folder:
cd ~/Sites/%production_url%
- Copy the example.local.config.yml and save as local.config.yml:
cp dvm/example.local.config.yml dvm/local.config.yml
- Edit the local.config.yml and update the "ssh_username" with your ssh login name:
vi dvm/local.config.yml
- Bring up Vagrant (This might take a while!):
vagrant up
- Once complete, Vagrant will open the dashboard in your default browser - http://dashboard.%vagrant_hostname%. Your site should now be available at https://%vagrant_hostname%
If vagrant throws an error on vagrant up
:
- Try updating your Vagrant box:
vagrant box update
and runvagrant up --provision
. - Run
vagrant box list
to see if the box "%vagrant_box%" exists. If it does, remove it withvagrant box remove %vagrant_box%
then runvagrant up
again.
If you get an "ECDSA host key" error, check your "known_host" file sudo vi ~/.ssh/known_hosts
for instances of "%vagrant_hostname%" - most likely at the bottom of the file. Remove the line and save the file. Then, run vagrant up
again.
The site install should have added Drush aliases for the available environments. They are as follows:
- @%project_name%.local - For your local VM, https://%vagrant_hostname%
- @%project_name%.stage - For the staging site at https://%stage.alias_uri%
- @%project_name%.dev - For the development site set up at https://%dev.alias_uri%
- @%project_name%.prod - For the production site at https://%production_url%.
To use these, cd into the (core Drupal file): cd %drupal_core_path%
(or from anywhere if Drush is installed globally on your machine.) and run your Drush commands, e.g., drush @%project_name%.local status
.
Note: This step may no longer be required.
If needed, install your public key: cat ~/.ssh/id_rsa.pub | ssh vagrant@%vagrant_autoip% 'cat >> .ssh/authorized_keys'
For the local alias, the default password for user "vagrant" is "vagrant." All other aliases should use your normal login info following the example given.
Images and other files are updated automatically on your local through the Stage File Proxy module.
Implementing a recent version of Production database is now a part of the initialization process of the Vagrant build. If your site launches without a database install or you wish to update your local with what is currently on production, follow the instructions below.
To update your data to what is currently available on Production, download a recent backup by logging into the %project_name% Prod site and go to Backup and Migrate. From here, you can either generate a new backup or download a recent file from the "Saved backups" tab. (You will need Admin access to %project_name% in order to do this.)
With the downloaded file, do one of the following tasks:
- Go to Backup and Migrate on your local site and restore the database with your backup file.
- Using Drush, sync from the SQL dump file with:
drush @%project_name%.local sql-cli < %vagrant_local_path%/*.mysql.gz
- Import the backup through other third party software (e.g.: Sequel Pro) using the SQL settings found on the dashboard.
Since this Vagrant install uses "vagrant-hostsupdater" to write to the /etc/hosts file, the up/halt/reload processes will persistently ask for sudo password information. This can cause problems when trying to run vagrant from programs like PHPStorm, where it might not typically run askpass processes.
To bypass this, you will need to make modifications to your sudoers file to give Vagrant permission to write to the hosts file. You can do this by following these steps:
-
From the command line, edit the sudoers file by running
sudo visudo
-
Scroll to the bottom of the file and type
i
to enter "insert mode" -
Insert the following code:
# vagrant-hostsupdater Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts %admin ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE # end vagrant-hostsupdater # vagrant-nfs Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports %admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE # end vagrant-nfs
-
Type
:wq
to save the changes and exit the sudoers file -
Restart your terminal sessions to apply the changes (in some cases, rebooting the computer works best.)
-
You should now be able to run
vagrant up
without the password requirement.
Note - The above code should work as expected from most MacOS environments. Other environments may require updates to the system paths (particularly the path to sed). Use "which" from the command line to determine your system path (e.g., which sed
).
For more information, review the "Helpful modifications to /etc/sudoers" section of this post from Jeff Geerling's blog.
More documentation on the Drupal VM project can be found at http://docs.drupalvm.com/en/latest