I’m a big fan of Laravel’s Valet for local WordPress development. However after wasting a day attempting to fix a bug with Valet I decided to give Local by Flywheel a try. Spending my day attempting to resolve an obscure bug with Valet is not a good use of my time. I rather be coding.
Local by Flywheel works by using a virtual machine. It’s one of the reasons I was avoiding using Local. VMs run slower and add extra complexities as compared to hosting websites with a local Nginx server (like Valet does). Here is a recap of my first day digging into Local.
Web request to other locally hosted application will fail.
Let’s say your WordPress site needs to make a request to
localhost:8000 for another service, like Fathom, which is hosted on your local machine. That request is going fail with Local due to the fact that localhost and 127.0.0.1 reference the virtual machine not the host machine.
A workaround I came up with involves finding the host machine’s virtual IP. On MacOs run
ifconfig and look for the
vboxnet0 adaptor. Should look something like this.
vboxnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 ether 00:a0:00:42:00:00 inet 192.168.95.1 netmask 0xffffff00 broadcast 192.168.95.255
Based on that, we can use
192.168.95.1 to talk back to the host machine. With my WordPress site I changed
192.168.95.1 and which resolved that issue.
Timezone not in sync
My WordPress website makes API requests to other services like Constellix. These API requests are time sensitive. Constellix started to response with the error: Bad timestamp! The timestamp is either expired or in the future. I figured this was due to the fact that the VM was running a different time then my local computer. I was correct. Running
date "+%Y-%m-%d %H:%M:%S" on both my command line and the VM’s revealed the difference.
- 2019-07-11 20:19:37 – My computer
- 2019-07-12 00:59:48 – Local’s VM
dpkg-reconfigure --frontend noninteractive tzdata will reveal the current zone info. Local’s default is
Etc/UTC however it should really be in sync with the host computer. In order to correct I made a backup of the current localtime file and created a symlink to my timezone.
mv /etc/localtime /etc/localtime.old ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
What is the underlying virtual machine?
Local installs VirtualBox so that it can run a virtual machine which is used to host it’s local websites. You can see the VM running in the background by opening up VirutalBox.
Each site then spins up a new docker on the VM which can be accessed with SSH.
cat /etc/os-release reveals it’s a Linux machine running Debian.
PRETTY_NAME="Debian GNU/Linux 8 (jessie)" NAME="Debian GNU/Linux" VERSION_ID="8" VERSION="8 (jessie)" ID=debian HOME_URL="http://www.debian.org/" SUPPORT_URL="http://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
The default VM is fairly stripped down. None of the common commands like
ping come preinstalled. Luckily new software can easily be added by running
apt update && apt upgrade then
apt install <app>. A one liner like
apt install curl git git-core iputils-ping takes care of those applications.
The default shell is bash. This too can be changed. I like using ZSH with Oh My Zsh. ZSH can be installed by running
apt install zsh. Without knowing Local’s root password
chsh -s $(which zsh) fails to make ZSH the default shell. Alternatively add
/usr/bin/zsh to the bottom of
~/.bashrc and reopen SSH and it should be running ZSH. Next install Oh My Zsh and now this is beginning to feel like home once again.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
I will say it’s nice to use something that just works out of the box. Local’s use of VMs under the hood does slow down website responses however it’s unlikely that I’ll ever run into the conflict issues I was experiencing with Valet. That’s due to the VMs isolation. For this reason alone I’m ok to take a small performance hit for something that just works. And for those that do like to tinker, like me, there is a whole world opened up by exploring Local’s SSH capabilities.