Quite often, I get inquiries from developers about how to get Drupal VM working on Windows 10—and this is often after encountering error after error due to many different factors. Just for starters, I'll give a few tips for success when using Drupal VM (or most any Linux-centric dev tooling or programming languages) on Windows 10:
- If at all possible, run as much as possible in the Windows Subsystem for Linux with Ubuntu Bash. Some things don't work here yet (like calling Windows binaries from WSL), but hopefully a lot will be improved by the next Windows 10 update (slated for Q2 2017). It's basically an Ubuntu 14.04 CLI running inside Windows.
- When using Vagrant, run
vagrant plugin install vagrant-vbguest
andvagrant plugin install vagrant-hostsupdater
. These two plugins make a lot of little issues go away. - If you need to use SSH keys for anything, remember that the private key (
id_rsa
) is secret. Don't share it out! The public key (e.g.id_rsa.pub
) can be shared freely and should be added to your GitHub, Acquia, etc. accounts. And you can take one public/private key pair and put it anywhere (e.g. copy it from your Mac to PC, inside a VM, wherever). Just be careful to protect the private key from prying eyes. - If you're getting errors with any step along the way, copy out parts of the error message that seem relevant and search Google and/or the Drupal VM issue queue. Chances are 20 other people have run into the exact problem before. There's a reason I ask everyone to submit issues to the GitHub tracker and not to my email!
Now, down to the nitty-gritty. One group of developers had a requirement that everyone only use Windows 10 to do everything. On most projects I'm involved with, at least one or two developers will have a Linux or macOS environment, and that person would be the one to set up BLT.
But if you need to set up BLT and Drupal VM entirely within Windows, there are a few things you need to do unique to the Windows environment, due to the fact that Windows handles CLIs, line endings, and symlinks differently than other OSes.
I created a video/screencast of the entire process (just to prove to myself it was reliably able to be rebuilt), which I've embedded below, and I'll also post the detailed step-by-step instructions (with extra notes and cautionary asides) below.
Video / Screencast
Step-by-step instructions
- Install the Windows Subsystem for Linux with Ubuntu Bash.
- Install Vagrant.
- You should also install the following:
vagrant plugin install vagrant-vbguest
andvagrant plugin install vagrant-hostsupdater
. This helps make things go more smoothly.
- You should also install the following:
- Install VirtualBox.
- Open Ubuntu Bash.
- Install PHP and Composer (no need for Node.js at this time) following these BLT Windows install directions.
- Set up your Git username and password following these BLT directions.
- Run the commands inside the BLT - creating a new project guide.
- Note that the
composer create-project
command could take a while (5-10 minutes usually, but could be slower). - If it looks like it's not really doing anything, try pressing a key (like down arrow); the Ubuntu Bash environment can get temporarily locked up if you accidentally scroll down.
- Note that the
- When you get to the
blt vm
step, run that command, but expect it to fail with a red error message (as of Windows 10 Anniversary Update the WSL can't easily call out to Windows executables from the Ubuntu Bash environment... therefore it fails to see that VirtualBox is installed in Windows since it's only able to see executables in the Ubuntu virtual environment.). - Install Cmder (preferred), Cygwin, or Git for Windows.
- Open Cmder.
- You need to run Cmder as an administrator (otherwise BLT's Composer-based symlinks go nuts). In Cmder, right-click on the toolbar, click 'New Console...', then check the 'Run as administrator' checkbox and click Start.
- You can use other Bash emulators for this (e.g. Cygwin, Git Bash, etc.) as long as they support SSH and are run as Administrator.
- When Microsoft releases the Windows 10 update post-Anniversary-update, the WSL might be able to do everything. But right now it's close to impossible to reliably call Windows native exe's from Ubuntu Bash, so don't even try it.
cd
into the directory created by thecomposer create-project
command (e.g.projectname
).- Note that Ubuntu Bash's home directory is located in your Windows user's home directory, in a path like
C:\Users\[windows-username]\AppData\Local\lxss\home\[ubuntu-username]
.
- Note that Ubuntu Bash's home directory is located in your Windows user's home directory, in a path like
- Run
vagrant up
to build Drupal VM.- Note that it will take anywhere from 5-25 minutes to bring up Drupal VM, depending on your PC's speed and Internet connection.
- Once
vagrant up
completes, runvagrant ssh
to log into the VM. - From this point on, all or most of your local environment management will take place inside the VM!
- Make sure you add your SSH private key to the Vagrant user account inside Drupal VM (so you can perform actions on the codebase wherever you host it (e.g. BitBucket, GitHub, GitLab, etc.) and through Acquia Cloud).
- You can create a new key pair with
ssh-keygen -t rsa -b 4096 -C "[email protected]"
if you don't have one already. - Make sure your SSH public key (
id_rsa.pub
contents) is also in your Acquia Cloud account (under 'Credentials'), and GitHub (under 'SSH Keys') or whatever source repository your team uses.
- You can create a new key pair with
- Inside the VM,
cd
into the project directory (cd /var/www/[projectname]
). - Delete Composer's vendor/bin directory so Composer can set it up correctly inside the VM:
sudo rm -rf vendor/bin
. - Run
composer install
.- If this fails the first time, you may be running a version of BLT that requires this patch. If so, run the command
sudo apt-get install -y php5.6-bz2
(using thephp_version
you have configured inbox/config.yml
in place of5.6
). - If this has weird failures about paths to blt or phing, you might not be running Cmder as an administrator. Restart the entire process from #12 above.
- If this fails the first time, you may be running a version of BLT that requires this patch. If so, run the command
- Run
blt local:setup
to install the project locally inside Drupal VM.- If this fails with a warning about
insecure_private_key
or something along those lines, you need to edit yourblt/project.local.yml
file and update thedrush.aliases.local
key toself
(instead ofprojectname.local
). BLT presumes you'll runblt
commands outside the VM, but when you run them inside, you need to override this behavior.
- If this fails with a warning about
- On your host machine, open up a browser and navigate to
http://local.projectname.com/
(where the URL is the one you have configured inblt/project.yml
underproject.local.hostname
).
CONGRATULATIONS! If all goes well, you should have a BLT-generated project running inside Drupal VM on your Windows 10 PC! You win the Internet for the day.
Next Steps
If you want to push this new BLT-generated project to a Git repository, make sure you have a public/private key pair set up inside Drupal VM, then in the project root, add the remote Git repository as a new remote
(e.g. git remote add origin [email protected]:path/to/repo.git
), then push your code to the new remote (e.g. git push -u origin master
).
Now, other developers can pull down the codebase, follow a similar setup routine to run composer install
, then bring up the VM and start working inside the VM environment as well!
Comments
In step 19 you can also run sudo apt-get install vagrant then vagrant ssh (which will fail). This generates the insecure private key.
@andy - quite true, and that way the drush command will work inside the VM just the same as outside—however that way feels slightly more of a hack than setting the drush alias to @self. Though if you do work both outside and inside the VM a lot, then it's probably the best middle ground. Thanks for the tip!
Know that this is now somewhat old instructions. Still one more thing to add at step 17, deleting only bin directory did not work for me. Had to remove whole vendor directory and re-run the 'composer install' worked for me.
Any changes to this doc for 2020? Is it still valid?
Unfortunately, there's a good chance some things have changed. It's been a couple years since the last time I worked with a BLT project.
When i run "blt vm" command as mentioned in Step:8, am getting the following error "warning: Insecure world writable dir /mnt/c in PATH, mode 040777". So this is causing an issue in step:12 throwing error like "Box 'geerlingguy/drupal-vm' could not be found" when i run "vagrant up" command. Any thoughts on this.?