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 software for the local WordPress development environment.
In the early days of my WordPress themes and plugins development in the local environment, I used the 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.
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 “Error: Error establishing a database connection.” error message.
In this tutorial, I will show you the steps to fix that problem.
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.
Find the “DB_HOST” constant from that file. We are going to update the value of that constant in the upcoming steps.
Now, open the Local application. Navigate to your current running site (check the green circle) and go to “Database” tab.
Copy the socket value and back to the wp-config.php file.
Add the socket value after the “localhost” text. Add a colon(:) between these two values. Here is the example screenshot.
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 of fixing the WP-CLI scaffold and Local issue.