Get in Touch

Please enable JavaScript in your browser to complete this form.
Email

Local By Flywheel + WP CLI

Time to Read:

1 minute

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', 'localhost: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 socket 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
How your folder structure will look like

You can add find socket info from your flywheel interface. Go to project > database > socket
You will have something like /Users/your_user_name/Library/Application Support/Local/run/project_id/mysql/mysqld.sock

<?php
define('DB_HOST', 'localhost:/Users/your_user_name/Library/Application Support/Local/run/project_id/mysql/mysqld.sock');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');

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

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

wp option get siteurl

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Posts

Filter