Installing WordPress using WP-CLI

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 --url=wordpress.dev --title="WordPress Dev" --admin_user=admin --admin_password=password --admin_email=yourEmail@gmail.com

    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’re just a quick config away!

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 though. 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 you use this process with an existing WordPress database. For example if you’re rebuilding a site, fixing one after a security breach or other reasons. Regardless of the situation, if you’re connecting to an existing WordPress instead of setting up a fresh one you’ll do this instead of using step 4 above!

wp core install --url=wordpress.dev --title="WordPress Dev" --admin_user=admin --admin_password=password --admin_email=yourEmail@gmail.com

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

 

 

Be Sociable, Share!

Author Bio

About the Author: Dan Pock

Dan Pock does Technical Writing & Marketing at Liquid Web with a background in System Administration, Public Relations, and Customer Service.

His favorite things include: his cats, Oscar Boots and Dash Nouget; experimenting with PHP; and making up recipes (or at least attempting to). You can find his coding hijinks on GitHub, where he shares most of his projects and open source work.

Here's 75 % off, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support