The WP-CLI is a fantastic command-line tool for WordPress developers. You can do almost everything related to WordPress using this command-line tool. On the other hand, Local is another outstanding piece of software for the local WordPress development environment.

In the early days of my WordPress themes and plugins development in the local environment, I used XAMPP. However, creating a WordPress site every time for new projects is extra work and takes a reasonable amount of time. So, I switched from XAMPP to Local.

Fix the WP-CLI scaffold and Local issue

Recently, I found some issues while working on a WordPress project and trying to create a custom WordPress plugin. I tried to create the plugin boilerplate using the WP-CLI scaffold command. But, getting an “Error: Error establishing a database connection.” error message.

Steps of Fix the WP-CLI scaffold and Local issue

Step 01

Navigate to the root of the WordPress installation. For local, it is “<YOURSITE>/app/public/”. Open the wp-config.php file using any code editor. I preferred to edit the code using Visual Studio Code.

Step 02

Find the “DB_HOST” constant from that file. We are going to update the value of that constant in the upcoming steps.

Step 03

Now, open the Local application. Navigate to your current running site (check the green circle) and go to “Database” tab.

Step 04

Copy the socket value and go back to the wp-config.php file.

Step 05

Add the socket value after the “localhost” text. Add a colon(:) between these two values. Here is the example screenshot.

Step 06

Save the wp-config.php file. Now, again, run the wp scaffold plugin my-wp-plugin command. A new plugin will be created successfully.

Now, you know the solution to fixing the WP-CLI scaffold and local issue.

Leave a Comment

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

*
*

Back To Top