It has been more than a year since I switched to Local by Flywheel for the local development of WordPress websites. I must admit that it is one of the best tools available for local development 💯 Local by Flywheel uses Docker to create WordPress sites in separate containers.
One thing that stuck out after switching was the use of WP-CLI 👀 WP-CLI is an essential tool for WordPress developers because it helps to speed up our workflow. However, to access the CLI for a website on Local by Flywheel, you have to go through a two-step process.
✅ Right-click on the name of the website in Local and select Open Site SSH. As a result, a new terminal window will appear which will automatically log you in via SSH protocol, and then WP-CLI becomes available for you.
💡 So, to streamline my workflow, I started searching for a solution which does not require logging into the container to access the CLI. And I made a CLI of my own, local-wpcli
✅ Introducing local-wpcli
local-wpcli creates configuration files which enable WP-CLI — installed on your computer — to connect with locally hosted websites of Local by Flywheel within your terminal. Use the following command in your terminal to install it globally.
npm install --global local-wpcli
⚙️ How it Works
Once the installation is complete, follow these steps to connect WP-CLI with your WordPress site.
- 1️⃣ Open your terminal and go to the root folder of the website.
cd ~/local-sites/local-wp/
- 2️⃣ Now input the following command and press enter.
local-wpcli
- 3️⃣ The CLI will ask the following details:
→ Remote Host (IP Address) — default is192.168.95.100
→ Remote Port
👉 You can find the details mentioned above in DATABASE tab of the website in Local by Flywheel’s desktop app.
The CLI creates two configuration files in the root folder namely,
- 1️⃣ wp-cli.local.yml
- 2️⃣ wp-cli.local.php
That’s it 🎉 Once the files are created, WP-CLI will be ready to use to your heart’s content 🙌
Stefano Monteiro says:
Do we need to have wp-cli installed?
May 3, 2019 — 7:31 am
Ashar Irfan says:
Yes,
wp-cli
should be installed on your system.May 3, 2019 — 7:38 pm
florianbrunner says:
I get the error “/bin/sh: wp: command not found” – what do I have to do?
November 13, 2019 — 9:01 pm
Luyen Dao says:
Thanks!!!
November 10, 2020 — 12:38 am
luyenminhdao says:
Any idea why i don’t see a Remote Host and Remote port on my Local WP? What would the default port be?
November 25, 2020 — 11:46 am
Ashar Irfan says:
That’s because the CLI does not support Local Lightning yet. I am tracking this issue over here.
November 25, 2020 — 6:39 pm
mike says:
This whole workflow doesn’t work now that Local has switched to sockets.
January 11, 2021 — 3:42 pm
Ashar Irfan says:
Yes, at the moment it does not work because of the switch to sockets. I am tracking this issue over here.
August 8, 2021 — 11:13 pm
Niloy says:
the fun thing is i am using local by flywheel since 2017 and today i know it’s have build in wp-cli 😀
November 23, 2021 — 9:55 am