With this entry I start a series of articles on WP-CLI (WordPress Command Line Interface).
WP-CLI is a tool that allows us to perform actions such as installing WordPress, activate / deactivate a plugin, create users, change passwords, set configurations, create test content, regenerate thumbnails, etc… all from the command line.
As a developer, with the command line interface you can improve productivity and automate tasks or processes.
On the official WP-CLI website you will find how to install it in a Linux-based environment. In this first post we will see how to install it in a Windows environment.WP-CLI simple installation guide Click To Tweet
Installing WP-CLI in Windows
The first thing you will need is to have PHP. If you have installed Xampp, Wamp or Mamp, the first thing is to create an environment variable to execute php simply by typing php in the command line. For it:
- Access the Control Panel
- Click on System and Security
- Click on System
- In the side menu look for advanced system configuration and click.
- In the Advanced tab , look for the environment variables button
- In System Variables look for Path and click on Edit
- Add a new one with the path to the php folder of your system. For example: C: \ xampp \ php \
Open the terminal and type PATH . Make sure there is a route to PHP that we have created. Then type php -v , you should get something like this:
PHP 5.6.21 (cli) (built: Apr 27 2016 20:13:54)
Copyright (c) 1997–2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998–2016 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002–2014, by Derick Rethans
The next thing is to install CURL . You can download the appropriate version to your system from here . Extract the .zip files and copy the curl.exe file that you will find in the / src folder to the % windir% folder (where Windows is installed). More info here .
Now that we have CURL and PHP, we are going to download WP-CLI. Execute the following command:
curl -O https://raw.githubusercontent.com/wp–cli/builds/gh–pages/phar/wp–cli.phar
Or you can download it directly from here .
Now, if you are running on the php
-- command line wp-cli.phar info , something like this should appear:
C:\xampp\htdocs>php wp–cli.phar —info PHP binary: C:\xampp\php\php.exe PHP version: 5.6.21 php.ini used: C:\xampp\php\php.ini WP–CLI root dir: phar://wp–cli.phar WP–CLI vendor dir: phar://wp–cli.phar/vendor WP_CLI phar path: C:\xampp\htdocs WP–CLI packages dir: WP–CLI global config: WP–CLI project config: WP–CLI version: 1.3.0
To simplify the use of WP-CLI and invoke it by simply typing wp on the command line, move the wp-cli.phar file inside the C: \ Users \ your_user \ bin (if it does not exist, create it).
Next, in the same folder create a wp.bat file and write these lines inside:
php “%BIN_TARGET%” %*
We’re almost there, go back to the environment variables through the Control Panel as we have done before, but this time see User Variables. Edit PATH and add “C: \ Users \ your_user \ bin”.
Restart the console and simply type wp
--info . If you have done everything right, you should get the same information as before when we run php wp-cli.phar
You have more detailed information about this process here .
So far the first chapter of this series. In the following we will see how to install a WordPress from the command line and make the first configurations.
[su_box title=”Note” box_color=”#d9f2cc”]In Windows, all functions and / or features of WP-CLI are not available.[/su_box]