# Windows Sage Setup Provisioner

**URL:** https://discourse.roots.io/t/windows-sage-setup-provisioner/4690
**Category:** sage
**Created:** 2015-09-06T16:35:21Z
**Posts:** 5

## Post 1 by @DemaniClassic — 2015-09-06T16:35:21Z

Hi,

I have created a [bash script](https://gist.github.com/darrienworth/05b68adf245e5fc7912a "bash script") that will automatically setup sage for Windows users.

This has been tested with **Windows 8.1** and the most recent version of **Trellis** as of 9/6/15.

This solves the lengthy process that must be completed after every **‘vagrant up’** or **‘vagrant destroy’**

It completes many of the steps that I have described in the post below.

> [@Setting up Sage on Windows 8.1](https://discourse.roots.io/t/setting-up-sage-on-windows-8-1/4407):
>
> In order to get Sage working properly on Windows 8.1, you’ll need to complete these steps before your first ‘vagrant up’ As of 8/5/15, this works with lastest release of Trellis, Bedrock, & Sage. Requirements: Windows 8.1 PC Host Vagrant 1.7.4 Virtualbox 4.3.30 Vagrant-hostsupdater plugin vagrant-winnfsd Putty SSH Client (Windows doesn’t come with one) PuttyGen (Generates SSH Keys) – \*\*\*Symlinks did not work when using VirtualBox 5.0.0 I believe it has something to do with the vagra…

**Soon I wll update this script to handle all of the file changes that must be handled on the VM in order to get the entire Trellis, Bedrock, Sage stack running.**

But for now, this script will:

- Creates node\_modules folder & copies package.json from theme to  
/srv/www/sitename.com on VM

- Installs nodejs & npm

- Fixes permissions to run npm without sudo & get latest npm

- Installs gulp and Bower globally

- Creates a symlink between node\_modules in theme folder and the one created on the VM by the script. NPM directories are not written back to the Window’s host machine in order to bypass Window’s 260 character file length limit.

- Installs npm & bower locally in theme

- Fixes [hosts executable error](https://discourse.roots.io/t/deploying-from-windows/4434/3 "hosts executable error") which prevents deploys & provisions

**Before you run this script, you will need to:**

Enable symlinks between (L)ocal and (R)emote machines on Windows host.  
Run the following command in an admin command prompt and then restart your machine  
for it to take effect. This command enables all forms of symlinks between local and  
remote machines.

```
fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1
```

By default, VirtualBox disables symlinks for security reasons. So we need to add this  
to our Vagrantfile.

```
config.vm.provider "virtualbox" do |vb|
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/current", "1"]
end
```

As of 8/5/15 Symlinks **did not** work when using VirtualBox 5.0.0  
I believe it has something to do with the vagrant guest additions, but I’m no expert.

* * *

I’ve included

[**windows-sage.sh**](https://gist.github.com/darrienworth/05b68adf245e5fc7912a#file-windows-sage-sh "windows-sage.sh")  
[**Vagrantfile** - For your reference](https://gist.github.com/darrienworth/05b68adf245e5fc7912a#file-vagrantfile "Vagrantfile")

[https://gist.github.com/darrienworth/05b68adf245e5fc7912a](https://gist.github.com/darrienworth/05b68adf245e5fc7912a)

**If you see any errors while the script is running, try running it a second time.**

* * *

**Tips for speeding up Sage on the development server**  
In some cases the default shared folder implementations (such as VirtualBox shared folders) have high performance penalties. If you’re seeing less than ideal performance with synced folders, NFS can offer a solution. The bigger your project, the slower your development web server will run. I had 5-6++ second page load times before implementing this solution.

Contrary to the [vagrant documentation](http://docs.vagrantup.com/v2/synced-folders/nfs.html "vagrant documentation"), there is an NFS solution for Windows called [winnfsd](https://github.com/winnfsd/vagrant-winnfsd "winnfsd").

Install it with the following command in the cmd prompt.

```
$ vagrant plugin install vagrant-winnfsd
```

**After your first ‘vagrant up’ and you have Trellis, Sage, Bedrock completely working and functional**

Open your Vagrantfile and comment out

```
config.vm.synced_folder local_site_path(site), remote_site_path(name), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775']
```

And add the following line below it

```
config.vm.synced_folder local_site_path(site), remote_site_path(name), type: 'nfs'
```

This is needed to give the development web server a major performance boost!

Run

```
vagrant reload --provision
```

**If you enable nfs in your Vagrantfile before your first vagrant up, you will receive an error. So you will need to toggle between the original line and the new line.**

Please let me know if you have any issues.

---

## Post 2 by @starise — 2015-09-20T04:21:29Z

Hi, your script is _unnecessarily_ complicated.  
I work on Windows 10 Pro using the default `windows.sh` included in trellis, taking care of run vagrant from an elevated powershell terminal.

Installing npm globally is not optimal. A better way to go is [nvm](https://github.com/creationix/nvm), that permits to install node in the user folder (`$HOME/.nvm`) and manage easily multiple version without getting crazy.

```
## Install latest version of nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
## Install latest nodejs version using nvm
nvm install stable
## Use stable version of node
nvm use stable
```

The only necessary part is symlinking the ‘node\_modules’ folder to bypass 260 chars limit. However this will be probably no more necessary starting from [npm 3](https://github.com/npm/npm/issues/3697).

---

## Post 3 by @DemaniClassic — 2015-09-21T14:40:51Z

Hi I appreciate the feedback.

The script I created was a list of all the steps I needed to run through before I could get sage properly working on my system.

I’m more of a designer than a developer, so I’m sure the script isn’t the best, but it allows me to destroy a VM and spin up another one without wanting to jump off a cliff.

I’m glad to see there’s another Windows user with a better way.

I’ll check out nvm.

---

## Post 4 by @starise — 2015-09-21T15:44:27Z

You’re welcome. :grinning: NVM is a lifesaver.  
I worked on gnu/linux for many years then i moved to Windows starting from 8.x, despite from what people say, maybe the best os i ever used. Today Windows is a good and fast all around operating system but can cause a lot of pain in some development stage. Fortunately Vagrant and modern tools like Trellis can give some relief.

---

## Post 5 by @DemaniClassic — 2015-09-21T16:18:29Z

Have you done anything in particular to speed up the development server?
