Setting up a local WP development

I’m trying to setup a local development on my new computer to allow me to easily create new wordpress themes. I’ve followed this guide - https://roots.io/guides/local-bedrock-development-with-local-by-flywheel/ and managed to get everything working.

But i was hoping to try out sage alongside this setup. Is this possible?

1 Like

After you’ve got flywheel set up, move on to the Sage docs. Specifically, head to your web/app/themes/ directory and run composer create-project roots/sage sage. This will install sage in your themes directory in a directory called sage. If you’re calling your theme something else you would do composer create-project roots/sage my-theme.

If you’re new to Sage, I highly recommend the book “Theme Development with Sage” available here.

1 Like

Hi ng3! Thanks for getting back to me. I couldn’t get on with local by flywheel after all. And didn’t like how it wasn’t supported by bedrock out of the box. So i tried using trellis instead. But i’ve ran in to another problem now, with that. I’ve been through the steps carefully and feel i’ve done everything correctly but for some reason i cannot get it to work!

Appreciate any help you can provide so i can finally get my environment up and running to build my wordpress theme. Please see attached.

What trellis command did you run to get the output in the first screenshot?

Hi alwaysblank!

I used vagrant up for the first window.

I see that you aren’t using WSL.
I’d recommend setting up your dev environment with WSL. Docs can be found here.

Hi codepuncher,

I tried doing that but i couldn’t get it to work either…

The advice in those docs to alias vagrant to vagrant.exe is incorrect (we need to remove it). You need to install Vagrant in WSL. Vagrant docs have some more information on this: https://www.vagrantup.com/docs/other/wsl.html

If you aren’t comfortable/familiar with these tools, Trellis is a pretty heavy solution for just spinning up a local development server (since it sounds like you won’t be using Trellis for remote provisioning or deploys). I’ve been using Homestead for local development when I’m not going to be provisioning remotely with Trellis.

Hi alwaysblank,

I just created a digital ocean account and was planning to use that to host my site. The instructions on that link seem a bit to complicated for me never having used the software before. Would you recommend that i use this Homestead instead?

I’m looking to do some freelance work so i’m wanting to create my main site and host it using bedrock and sage, and then further down the line making additional sites which i’d like to “stage” for people to view online.

Whats my best course of action?

If you want to be in full control of the management of your server, then I would recommend using Trellis to provision and deploy it. If you would rather let someone else manager your sever (which is what I prefer, unless I have a very compelling reason to take on the hassle and extra responsibility of server management and uptime), then I’d recommend just hosting on Kinsta. Their service is excellent and they allow SSH access, so you can use Trellis (or other systems) to do automated deploys.

The best course of action is whatever is the most comfortable and useful to you.

Literally tried everything and can’t get it to work… even uninstalled Ubuntu on windows and retried everything.

Early this afternoon a set up Trellis in WSL from scratch, so I know it’s viable. I followed the instructions in these two locations, with a few modifications:

The modifications:

  • The roots.io docs don’t currently mention this explicitly, but Vagrant in WSL will throw an error if you don’t have Vagrant also installed in Windows, with the exact same version in Windows and WSL.
  • Hosts updaters don’t seem to work, so you need to change your Windows hosts file manually.
  • There may be some permissions issues. There are two parts to fixing this.
    • This first is to add the following (or something like it) to /etc/wsl.conf, and then restart WSL:
      [automount]
      options = "metadata,umask=22,fmask=11"
      
    • The second is to apply correct permissions to your trellis directory (744 works for me) and the private key vagrant generates to access the VM (600 worked for me).
  • Make sure you use a version of Ansible lower than 2.8. 2.8 will throw an error.

I’ll bow out here as I know nothing about Windows. Good luck…

I’ll bow out here as I know nothing about Windows. Good luck…

Thank you for your assistance anyway!

Thank you, really appreciate the time you’ve taken to help me with this. I have followed all of the steps as carefully as i can. I have vagrant installed on both windows and ubuntu, through WSL. Both the same versions.

Everything seems to be working ok apart from when i use vagrant up.

ashley@DESKTOP-EKBG4DV:~/Sites/roots-example-project.com/trellis$ vagrant up
/home/ashley/Sites/roots-example-project.com/trellis/Vagrantfile:1: warning: already initialized constant ANSIBLE_PATH
/home/ashley/Sites/roots-example-project.com/trellis/Vagrantfile:1: warning: previous definition of ANSIBLE_PATH was here
/home/ashley/Sites/roots-example-project.com/trellis/Vagrantfile:2: warning: already initialized constant ANSIBLE_PATH_ON_VM
/home/ashley/Sites/roots-example-project.com/trellis/Vagrantfile:2: warning: previous definition of ANSIBLE_PATH_ON_VM was here
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

vm:
* The host path of the shared folder is not supported from WSL. Host
path of the shared folder must be located on a file system with
DrvFs type. Host path: /home/ashley/Sites/roots-example-project.com/site
* The host path of the shared folder is not supported from WSL. Host
path of the shared folder must be located on a file system with
DrvFs type. Host path: /home/ashley/Sites/roots-example-project.com/trellis
* The host path of the shared folder is not supported from WSL. Host
path of the shared folder must be located on a file system with
DrvFs type. Host path: /home/ashley/Sites/roots-example-project.com/trellis/bin
* The host path of the shared folder is not supported from WSL. Host
path of the shared folder must be located on a file system with
DrvFs type. Host path: .

I think the last time I used Windows and WSL, I stored the project in a different place.
In your comment above, I can see you have setup the example project inside the Linux storage (/home/ashley/).
Try setting up the project in /mnt/C/Users/your-windows-user/. If my memory serves me correct, that’s how I had it setup anyway.
This meant I could access the files in Windows and WSL.

Hi codepunhcer,

That seemed to do the trick!

ashley@DESKTOP-EKBG4DV:/mnt/c/Users/acell/Desktop/Sites/site1/trellis$ vagrant up
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:1: warning: already initialized constant ANSIBLE_PATH
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:1: warning: previous definition of ANSIBLE_PATH was here
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:2: warning: already initialized constant ANSIBLE_PATH_ON_VM
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:2: warning: previous definition of ANSIBLE_PATH_ON_VM was here
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-18.04' version '201906.18.0' is up to date...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
==> default: Running action triggers after up ...
==> default: Running trigger...
==> default: Adding vagrant ssh-config for roots-example-project.test to ~/.ssh/config
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:1: warning: already initialized constant ANSIBLE_PATH
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:1: warning: previous definition of ANSIBLE_PATH was here
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:2: warning: already initialized constant ANSIBLE_PATH_ON_VM
/mnt/c/Users/acell/Desktop/Sites/site1/trellis/Vagrantfile:2: warning: previous definition of ANSIBLE_PATH_ON_VM was here

==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default:
==> default: Your Trellis Vagrant box is ready to use!
==> default: * Composer and WP-CLI commands need to be run on the virtual machine
==> default:   for any post-provision modifications.
==> default: * You can SSH into the machine with `vagrant ssh`.
==> default: * Then navigate to your WordPress sites at `/srv/www`
==> default:   or to your Trellis files at `/home/vagrant/trellis`.

But for some reason when i got to https://roots-example-project.test/ it doesn’t load anything? Even though its saying running. And when running

yarn start

In the sage folder it opens localhost:3000 but again, nothing.

DONE Compiled successfully in 3958ms

Great!

Now, because the vagrant box is running inside WSL, either your domain has the wrong IP address in your hosts file or it hasn’t been added.
Once you’ve pointed the domain to your WSL Vagrant box IP address, you should be good to go!

Have you manually updated your Windows hosts file to point the correct domain to the correct IP?

Great!

Now, because the vagrant box is running inside WSL, either your domain has the wrong IP address in your hosts file or it hasn’t been added.
Once you’ve pointed the domain to your WSL Vagrant box IP address, you should be good to go!

Have you manually updated your Windows hosts file to point the correct domain to the correct IP?

Thank you both! But not quite sure what you mean. Where do i change/add this?

What have you tried to resolve the problem on your own? We’re happy to help you, but it’s helpful to us (and to you) if you try to solve problems on your own and detail your steps and their results instead of just asking us “I hit an error, what’s the next step?”

This is the first result on google for “change windows hosts file”:

You’ll need to point it to your VM’s IP, which can be found in your Trellis configuration: https://github.com/roots/roots-example-project.com/blob/ee20d3db6391f5809ec8e5015c2b8cffd9f40e8d/trellis/vagrant.default.yml#L2 (Or you could probably get this information from VirtualBox.)