Do you develop WordPress sites on Local by Flywheel, formerly Pressmatic?
(If not, you really should give it a go. It’s a great little tool for spinning up installs of WordPress quickly and with zero headache. But I digress… ?)
Do you ever find yourself wanting to access said sites from another computer on your local network?
It can be done! In this post, I’m going to walk you through how I hacked my way to Local sites that I can easily access from my laptop, even though they’re actually “hosted” on my iMac.
There currently isn’t an official Flywheel solution to this problem, hence the hacking. According to this post in the Local support forums, the Local team plans on adding Live Tunnel in the future, but for now this is the best (and cheapest) solution I’ve found.
Note: Proceed with caution! If you don’t follow these instructions exactly, you could render your Local sites inaccessible. Make sure you’re comfortable with the tasks at hand before you begin. This guide was written for OS X, so keep that in mind if you’re using another operating system.
Step-by-step guide to making Local by Flywheel sites accessible across your local network
Step 1: download and install some additional software
Download VirtualBox admin + the Oracle VM VirtualBox extension pack from the VirtualBox website: https://www.virtualbox.org/wiki/Downloads. We’ll be using these two things to gain access to the underlying server that Local runs.
For VirtualBox, you want to select the appropriate operating system from the list beneath “VirtualBox X.X.X platform packages,” where the X’s are replaced by VirtualBox’s current version number (5.2.20 at the time of writing this post). Install the package.
After you’ve installed VirtualBox, you can install the extension pack. There’s only one downloadable file for the extension pack; you don’t have to worry about getting the right file for your OS here.
Step 2: Edit the Local virtual machine’s network settings
- We’ll start by opening up VirtualBox. Once it’s fully initialized, you should see a virtual machine (or VM) named “local-by-flywheel”.
- Click the name of this VM, then either click the Settings button in the toolbar above (it has a gear icon) or right-click the VM and select “Settings…”
- A modal will appear with the VM’s settings. Go to the Network tab, which has an icon with two monitors.
- There should already be Network adapters set up under Adapter 1 and Adapter 2. Go to Adapter 3.
- Check the “Enable network adapter” box
- Select the following settings:
- Attached to: Bridged adapter
- Name: en1: Wi-fi (Airport) – this will likely vary for you, but look for a wireless networking option here
- In advanced settings, check “cable connected” box
- Click the “Ok” button to save your new VM settings
Step 3: restart the Local VM and make note of IP address
- Still in VirtualBox with the “local-by-flywheel” VM selected, click the Start (or Show) button in the toolbar, or right-click on the VM and choose Start or Show (The show option means your VM is already running).
- A new window will appear; this window is your Local VM. Once the VM is loaded, hover over the icon of two monitors at the bottom of the VM window. This is the same icon you saw in the VM settings panel for Network.
- A tooltip will pop up with information for all of your VM’s network adapters. Under Adapter 3 (Bridged adapter), make note of the IP address. This is the IP we will use to access our Local sites from our other machine.
- Close the new VM window and select “save the machine state” when you’re prompted for an option. Once the VM shuts down, the window will disappear.
- Back in VirtualBox with the “local-by-flywheel” VM selected, click the arrow next to the start button and select “Headless start”, or right-click on the VM and select “Headless start” from the menu under Start. This will start the Local VM without the window we saw earlier, which is the normal way Local operates.
Step 4: change hosts file on your other machines
- From the other computer you want to use to access Local sites, open up your hosts file. On OS X, this is located at “/etc/hosts”. Since this is a system file, you may need to use the Terminal to open the file so that you can sudo, giving yourself temporary superuser permissions.
- OS X example: With the Terminal open, type “sudo nano /etc/hosts” and press return. Type the password for your current user when prompted (nothing will display on the screen), and press return again. The hosts file will open in nano, a command-line text editor.
- Add a new line for each Local site you’d like to view with the site’s domain name and the IP address you noted in Step 3.
- Ex: plugin.test 192.168.1.12
- Save and close the file.
- OS X example: Control + x to close file, then press y and return when prompted to save
Step 5: test!
Open up a browser window on the same computer you just used to edit your hosts file. Attempt to navigate to one of your Local sites (ex: https://plugin.test). If everything worked, you should be able to see and access the site just like you can on your machine that actually runs the Local program!
Note: whenever you restart Local (not an individual Local site, but the entire program), you’ll need to double-check your VM’s networking settings to see if your bridged adapter has been assigned a new IP address by your router. If so, you should repeat Step #4 with the new IP address. This is always the first thing to check if your Local sites are no longer working from another computer!
Tips for editing Local sites on other machines
The main reason I set up my Local sites in this way is to make development easier: I can edit the same Local site from my iMac and my Macbook Pro without having to copy changes to the database or file system when I swap machines.
To keep this whole process as hassle-free as possible:
- I use File Sharing between my Macs to edit the files of the site. I don’t keep a copy of the site files on my laptop; I just use Finder to wirelessly connect to my iMac and access the “original” site files.
- Since I’m using a task runner, I also use ssh to connect to my iMac from my laptop. This way, I can run terminal commands as if I’m sitting at my desktop….particularly useful for gulp and git!
- For preliminary mobile cross-browser testing, I use iOS Simulator or the Android emulator on one of my machines. That way, I don’t have to worry about uploading the site somewhere that’s publicly accessible just to start testing.
Taking it further
Want to make your setup even cooler? There are a couple of things you can try:
- Set up a static IP address for your Local VM so that you don’t need to make changes to your /etc/hosts file when Local restarts: https://superuser.com/questions/456057/static-ip-for-ubuntu-server-in-virtualbox-using-bridged-adapter
- Need a more robust solution? Check out http://xip.io/. It looks very promising, but I haven’t had the need to use it yet – hacking Local is enough for me at the moment. ?
Were you able to access your Local sites from another machine on your network after following these instructions? Got a better setup to recommend? Let me hear about it in the comments!