Site icon Digamber Pradhan

Local By Flywheel + WP CLI

At the time of writing this article – I am referring to Local version 6.1.2 – on Mac OS.

Local by flywheel is a fantastic tool for quick WordPress development.
However running CLI commands on WP CLI requires you to right click and open site ssh (on Mac OS).

To remedy this there is a two step process – i would suggest doing this at the very start of creating your project as this allows you to quickly use wp cli right from the command line.

Firstly – you need wp-cli installed globally. If you’re on a mac use Homebrew and intsall wp-cli brew https://formulae.brew.sh/formula/wp-cli

Then on the root of your project – add a wp-cli.local.php file

The content of which should be the following

<?php
define('DB_HOST', '127.0.0.1:xxx');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');

error_reporting(0);
@ini_set('display_errors', 0);
define( 'WP_DEBUG', false );

You will need to replace the xxx with your own port number. We will get to that in a second.

You will also need to add a wp-cli.local.yml file this should also be on the root folder of your local project. The content of which will be

path: app/public
require:
  - wp-cli.local.php


The Mac OS system uses sockets instead of ports so the port number is not available on the Local dashboard. To remedy this you should follow the steps shown here https://community.localwp.com/t/how-can-i-connect-to-mysql-using-tcp-ip-rather-than-a-socket-on-macos-linux/21220

Basically you need to SSH into your site and then run the following commands

mysql -e "CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root'; GRANT ALL ON *.* TO 'root'@'127.0.0.1';"

then run

mysql -e "SHOW VARIABLES WHERE Variable_name = 'port';"

Will reveal you to the port number – replace the ‘xxx’ in you wp-cli.local.php file with the port shown here.

After doing this, wp cli commands will be available right from your terminal or integrated IDE terminal.

You can try running a

wp option get siteurl

This should return the site url and indicate WP CLI is working

Exit mobile version