Back to Top

Install WordPress through WP-CLI in few seconds

Updated 1 October 2019

Install WordPress through WP-CLI – Everyone is probably familiar with WordPress and its renowned 5-minute install routine. It’s simple and works without fuss. But when you have multiple sites to manage, repeating the same routine can waste plenty of time which you could have used elsewhere.

This is where WP-CLI, a powerful command line tool with which you can manage WordPress, can help. This tutorial covers how to install WP-CLI and how to perform some common, practical tasks using it.

Install WP-CLI

  1. WP-CLI is available as a PHP Archive file (.phar). You can download it using either wget or curl commands:
    curl -O


  2. You need to make this .phar file executable and move it to /usr/local/bin so that it can be run directly:
    chmod +x wp-cli.phar
    sudo mv wp-cli.phar /usr/local/bin/wp
  3. Check if it is installed properly:
    wp --info

    You should see a similar output like that displayed above, which means you can proceed:

You can use the above three steps for upgrading WP-CLI as well.

Basics of WP-CLI

Before moving on, let’s learn some basics of how WP-CLI works. This will help you feel comfortable with the upcoming steps.

So far, we have seen WP-CLI accessed through the main command, wp. You can follow the main command with nested subcommands. For example, we have a command to download WordPress, which is:

Searching for an experienced
WordPress Company ?
Find out More
wp core download

Here wp is the main command while core and download are its nested subcommands. Nesting subcommands can extend one or two levels.

WP-CLI also comes with a detailed help section, which displays all the commands you might need. To access help:

wp help

The output should resemble:

: is a prompt that, with subcommands, can help you navigate through this help menu. Up and down arrow keys will let you scroll through the entire help command list. Typing q will exit the help menu. For additional details on how to further navigate through the complete help section, you can always type h at the above prompt.

You can use the enabled bash completion to demonstrate WP-CLI’s readily available command list. Simply type wp and press tab twice. You will see the list of available commands. Now, type wp core and press tab twice. You will see a list of commands that can be used with core. This double tabbing after a command can be repeated for any primary or subcommand.

Install WordPress

Setting up Database

  1. Before you proceed, you need to setup a database. Log in to the MySQL server, replacing user with your MySQL username:
    mysql -u user -p

  2. Create a database:
    create database wordpress;
  3. Grant required privileges to the database for the mysql user to which WordPress will permit database access. Replace user and password with those of the permitted mysql user:
    grant all on wordpress.* to 'user' identified by 'password';
  4. Type quit to exit the MySQL command line.

Main Install

  1. Move to the Apache test directory:
    cd /var/www/html/test
  2. Next, download the WordPress files.
    wp core download
  3. Create a wp-config.php file:
    wp core config --dbname=wordpress --dbuser=user --dbpass=password --dbhost=localhost --dbprefix=wp_

    dbhost and dbprefix are entirely optional and can be omitted unless you need to change their default values.

  4. Run the installation:
    wp core install --url="" --title="Blog Title" --admin_user="adminuser" --admin_password="password" --admin_email="[email protected]"

Your WordPress blog is now ready for use.

Common Commands

Installing Themes with WP-CLI

Importing and installing themes is much quicker through WP-CLI than going into WordPress admin, searching and then activating it.

It connects your server directly to the WordPress theme repository and imports the theme in a matter of a few seconds. For example, to install a theme like TwentyTen, we will use the following command:

wp theme install twentyten

To activate the themes on your WordPress website, you will need to use the following command:

wp theme activate twentyten

Installing Plugins with WP-CLI

Just like the themes, plugins can also be installed right from the official repository. Installation is seamless and takes almost no time.

wp plugin install woocommerce

The above command will install the WooCommerce plugin on your website. To activate it, we will use the command:

wp plugin activate woocommerce

Similarly, to deactivate any plugin, the command becomes:

wp plugin deactivate woocommerce

Updating WordPress Core, Themes and Plugins with WP-CLI

Repetitive and often time consuming task of updating the WordPress core, themes and plugins can be easily carried out through the command line.

To update the WordPress core to the latest stable release of WordPress, the command is:

wp core update

If you want to update to a specific version, for example you have WordPress 3.7 and want to move to WordPress 4.0 instead of WordPress 4.3, use the command:

wp core update --version=4.0

Or, if for any reason you want to revert back your WordPress site to the previous version, the command is:

wp core update --version=3.9 --force

To update plugins, you can either define one plugin to update or better still.

wp plugin update woocommerce

Update all the plugins in one go.

wp plugin update --all

A similar method applies to the themes. You can update WordPress themes through WP-CLI with following command

wp theme update twentyten

Update all the themes in one go.

wp theme update --all


WP-CLI is indeed a powerful tool that can be used to manage your WordPress sites through the command line. There are also many more commands to manage your database, take backups, manage posts, comments and WordPress multisite It definitely speeds up your tasks, and makes it really easy to manage the sites. Luckily, there are hosting providers that provide WP-CLI by default on their WordPress installations (you can find a maintained list here).

. . .

Leave a Comment

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

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home