WP-CLI is a command line interface that enables users to manage their WordPress websites from the command prompt, speeding up their development process. Using WP-CLI, a web admin can set up new websites, upgrade, back up, even create new posts and pages.
In this post I am going to demonstrate how to get started with WP-CLI if you work on Windows, using XAMPP on your computer, as WP-CLI can be installed on any UNIX-like enviroment.
How to get WP-CLI going
I am going to assume we have already XAMPP up and running on our local machine, so we can get going with WP-CLI.
In order to install WP-CLI on XAMPP, we have to download wp-cli.phar and save it in the /php directive of our XAMPP installation. We then move to the /php folder and create a wrapping batch script that will create wp.cmd in the folder:
echo @php "%~dp0wp-cli.phar" %* > wp.cmd
We can confirm that we have successfuly installed WP-CLI, by typing
anywhere in our system.
Use WP-CLI to install WordPress
First we create a new directory in /htdocs named wpcli and then we move to the directory with the command
and use the
wp core download
command to download WordPress:
After the success message, we can go to our new WordPress website: http://localhost/wpcli/wp-admin
Of course, we are greeted with the famous WordPress installation process, so we now have to create the database. We can use phpMyAdmin to do so and afterwards, we can set up the wp-config.php with the database credentials like this:
wp core config --dbname=database_name --dbuser=database_user --dbpass=user_password --dbhost=localhost --dbprefix=wp_
If we are greeted with the following message:
‘mysql’ is not recognized as an internal or external command, operable program or batch file.
we have to add MySQL to the enviroment variables of our local machine and open a new command window. Afterwards, the command line will look like this:
After the wp-config.php is created with the correct credentials, we finally get to run the WordPress installation script, along with basic information of the website and its administrator.
wp core install --url=localhost/wpcli --title=localhost/wpcli --admin_user=admin --admin_password=Strong_password --firstname.lastname@example.org
We can now go to localhost/wpcli and see our beautiful empty WordPress site.
Available WP-CLI Commands
Of course this is the tip of the iceberg as far as WP-CLI goes.
In order to list all the commands available with WP-CLI, we can type the following command:
In conclusion, this is how we can set up WP-CLI in our local machine using XAMPP. In a later post we are going to see more uses of the WP-CLI like backups, post creation, etc.