Reading Time: 3 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, using WP-CLI, and maybe a sprinkle of SSH.

In order to be able to install WordPress manually using WP-CLI you will first need to create a new database for the WordPress install. You will need to know how to find your SSH credentials as well as being used to using Terminal or Putty and WP-CLI.

Using WP-CLI to install WordPress

In this tutorial we’ll learn how to install WordPress using the WP-CLI command line tool. WP-CLI is a tool using in a terminal for interacting with and managing WordPress sites. WP-CLI is similar in functionality to what Drush provides Drupal. If you are already familiar with using cli tools then this will be an easy installation. Using WP-CLI, we can complete common maintenance tasks, automate processes, and even take backups.

Prerequisites

  • The latest version of WP-CLI Installed.
  • SSH Credentials to log into the server as the root user or a user with sudo privileges

Install WordPress

First, we will need to cd into the public_html folder where the WordPress install is going to reside.

root@host:~# cd ~/public_html/wpdev

Next, we will need to run the following WP-CLI command which will download the WordPress core files from the WordPress.org and then extract them into the public_html folder.

root@host:~# wp core download 

Now that we have the WordPress core files installed, the next task is to create our MySQL database. There are multiple ways to accomplish this, so we need to ensure we are doing what our server needs.

Do not copy the commands below directly!
These are only examples used for this tutorial.
Substitute your settings for these entries.

mysql -e "create database wpdev;";

Next, we will need to create a wp-config.php file for the site we just added which will contain the database name, database user and database password.

wp config create --dbname=cli1_wp_ --dbuser=cli1_wp --dbpass=Hippi3Pik3r5Ha1rDr@ms --locale=ro_RO

Now that we have created a valid wp-config.php file, it is time to go through the 5 second install process using WP-CLI's core installation command.

wp core install --url=wordpress.dev --title="WordPress Dev" --admin_user=wpadmin --admin_password=p@55w0ord! --admin_email=you@myemail.com 

Success: WordPress installed successfully.

Make sure that you update all the info for the arguments here. If you'll notice above, we change the URL for the domain, replacing it with the actual domain URL that is needed. We also changed the site's title, the admin username, the admin password, and finally, we set our email address for the admin user. Make sure the email is correct since WordPress will email you if your PHP can send email. We now have a working WordPress install.

To verify which version of WordPress we are running, we can run this WP-CLI command.

wp core version

Next, we need to create an appropriate Apache/Nginx vhost entry (if running in an unmanaged environment) and the needed PHP configuration changes, and then we are ready to go the new with WordPress setup.

If you're on a cPanel, InterWorx, or Plesk server, chances are you already have these settings created for you. If you create a cPanel, InterWorx or Plesk account for the WordPress install in advance. These tasks are performed automatically when you create the new account in the servers control panel. If you're on a traditional unmanaged server, we will need to create and modify the config files.

Things to Watch Out For!

Database related

One major item to be aware of when running through the process. If you forget to make the database and run the WP-CLI install, you will get an error. This also applies when you have entered the wrong credentials also. The errors will vary slightly depending on the situation, but they are both 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 WordPress For an existing WordPress database

Another thing to keep in mind is that if you employ this process using an existing WordPress database, we need to use the following command instead of the one used above.

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

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

A few examples of when this would be applicable. If you are rebuilding a site or fixing an account after a security breach, or for any other situation where you already have an existing database.

One last thing to keep in mind is that if you have a custom database prefix, or are using a remote MySQL server, you will have to add additional flags for those. You can see the full list of commands flags by running the following command.

wp core config --help

If you are experiencing problems installing WordPress this way, our support team can help. Simply give us a call today at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable System administrators!

Avatar for Luke Cavanagh

About the Author: Luke Cavanagh

Product Operations Manager at Liquid Web. Devoted husband and Tween wrangler. Synthwave enthusiast. Jerry Goldsmith fan. Doctor Who fan and related gubbins.

Latest Articles

Blocking IP or whitelisting IP addresses with UFW

Read Article

CentOS Linux 7 end of life migrations

Read Article

Use ChatGPT to diagnose and resolve server issues

Read Article

What is SDDC VMware?

Read Article

Best authentication practices for email senders

Read Article