Installing WordPress using WP-CLI

Reading Time: 2 minutes

WordPress has a great GUI based installation process however some use cases call for CLI! Or maybe you just feel more at home in a terminal, either way this article will show you how to get your WordPress site setup with just a terminal, WP-CLI, and maybe a sprinkle of SSH.

So first things first, if you’re doing this locally fire up your terminal and if you’re doing this on a server connect to it via SSH. Now that you’re in CLI you want to get into the folder you’re installing WordPress to. From there you can get things rolling in WordPress!

Using WP-CLI to install WordPress

  1. Get into the folder you’re installing WordPress
    If you need to create the folder first then change directory to it.
    cd ~/public_html/wpdev
  2. Now in the folder download the latest WordPress core files.
    wp core download

     Downloading WordPress 4.9.1 (en_US)...
    md5 hash verified: 111ecbfc98633103e1fc1105c0c00c76
    Success: WordPress downloaded.

    Just note, if you’ve already installed the newest version recently the second line will state it’s “using cached file…” instead.

  3. Now that you’ve got the WordPress core files installed the next thing you need to do is create your MySQL database. There’s a lot of ways to do this depending on your situation, so make sure you’re doing what your server needs. Don’t just copy these commands directly!
    mysql -e "create database wpdev;";
  4. With the database created now you can run the core install command!
    wp core install --title="WordPress Dev" --admin_user=admin --admin_password=password

    Success: WordPress installed successfully.

    Make sure that you update all the info for the arguments here. You should use your domain for URL, the name of your site for title and then obviously use your own user information! Make sure the email is right since WordPress will send you an email if your PHP can send email.

  5. Create an appropriate Apache/Nginx vhost and the needed PHP configs and boom! You’re ready to go with WordPress.
    If you’re on a cPanel, or Plesk, server then chances are you’ve already got this step in the bag. This is done automatically when you create your User for the website in the servers control panel. If you’re on a traditional unmanaged server then you just need to whip up a quick config file.

What to look out for!

Database related

One big thing to look out for when running through the process, if you forget to make the database and run the install you’ll get an error. Makes enough sense right? This also applies when you’ve entered the wrong credentials too. The errors will vary slightly depending on the situation, but their both pretty similar.
For example, when you provide the proper User and password for MySQL but didn’t make the database you’ll see:

Error: Can’t select database. We were able to connect to the database server (which means your username and password is okay) but not able to select the `wpdev` database.
Installing for an existing WordPress database

Another thing to keep in mind is that if you use this process with an existing WordPress database. For example if you’re rebuilding a site, fixing one after a security breach, or any other situation where you already have a database. No matter the case, if you’re connecting to an existing WordPress you’ll do this instead of using step 4 above!

wp config create --dbname=YourDB_Name --dbuser=WP_MYSQL --dbpass=WPDB_PASS

Success: Generated 'wp-config.php' file.

Keep in mind that if you have a custom database prefix, or are using a remote MySQL server, you’ll have to add additional flags for those. You can see the commands full flags by running:

wp core config --help

Author Bio

About the Author: David Singer

I am a g33k, Linux blogger, developer, student and Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Refer a friend and get a $50 hosting credit!