Install WordPress on pair Networks using wp-cli

This post describes how I installed WordPress on my pair Networks shared host using WP-CLI. WP-CLI provides a command line interface for installing and managing WordPress. I like using the Unix/Linux command line to install and maintain my website–it provides a lot of under-the-hood power and control. We will first talk about setting up WP-CLI before getting into the WordPress install.

As always, use your pair Networks username wherever you see “user1” in the below examples.

Install the WP-CLI executable, wp

pair Networks does have wp-cli installed in /usr/local/bin, but it’s an older version, as of this writing, so I used the procedure at WP-CLI to install the latest wp-cli executable in my local bin directory at /usr/home/user1/bin. The command is named “wp”. You need to ensure that your local bin directory is included in your “PATH” to executable commands. You should have a .bashrc file where you need to define this PATH. Be sure to include the PATH definition at the very beginning of your .bashrc file. This will be very important later when executing commands remotely. It should look something like:

PATH=/usr/home/user1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Make sure that your .profile includes the .bashrc file. You can add the following to your .profile:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

Exit your terminal window and log back in. If you followed the procedure at the WP-CLI website and set up your PATH, you should be able to test your WP-CLI install by doing:

user1@www2: /usr/home/user1
==> which wp
/usr/home/user1/bin/wp

user1@www2: /usr/home/user1
==> wp --info
OS:	Linux 4.4.0-139-generic #165~14.04.1-Ubuntu SMP Wed Oct 31 10:55:11 UTC 2018 x86_64
Shell:	/bin/bash
PHP binary:	/usr/local/bin/php71
PHP version:	7.1.22
php.ini used:	/usr/local/etc/php71/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/usr/home/user1
WP-CLI packages dir:	
WP-CLI global config:	/usr/home/user1/.wp-cli/config.yml
WP-CLI project config:	
WP-CLI version:	2.0.1

Note the “global config” file config.yml. You probably don’t have that defined yet. That’s OK, but your output should look similar to the above. If so, you are good to go.

Update the WP-CLI executable, wp

You can use “wp help” to view all kinds of information about how to use wp. Here are a couple of quick wp “cli” commands to check and update your installed version of wp:

user1@www2: /usr/home/user1
==> wp cli version     
WP-CLI 2.0.1

user1@www2: /usr/home/user1
==> wp cli check-update
+---------+-------------+-----------------------------------------------------------------------------+
| version | update_type | package_url                                                                 |
+---------+-------------+-----------------------------------------------------------------------------+
| 2.1.0   | minor       | https://github.com/wp-cli/wp-cli/releases/download/v2.1.0/wp-cli-2.1.0.phar |
+---------+-------------+-----------------------------------------------------------------------------+
 
user1@www2: /usr/home/user1
==> wp cli update 
You have version 2.0.1. Would you like to update to 2.1.0? [y/n] y
Downloading from https://github.com/wp-cli/wp-cli/releases/download/v2.1.0/wp-cli-2.1.0.phar...
md5 hash verified: fa0fb31d1462a5c39a8d4d2cdb369462
New version works. Proceeding to replace.
Success: Updated WP-CLI to 2.1.0.
 
user1@www2: /usr/home/user1
==> wp cli version
WP-CLI 2.1.0

Install WordPress using wp (WP-CLI)

Ok, now we are ready to install WordPress using wp (WP-CLI). I am making a few assumptions. First, you have added your website domain to your pair Networks account. Optionally, you have set up SSL for your website. You have verified that your domain name/website is working, for example, by entering your website name in Safari on your Mac. With an empty website directory, you should see “Index of /” displayed. You have set up an email address for your domain.

Next you need to create a database for your WordPress site using your Account Control Center (ACC).

The next step is to download WordPress. We will use wp to do the download. First, be sure to change directory to your domain name. Do the following (substitute your pair Networks username for “user1” and your domain name for “example.com”):

user1@www2: /usr/home/user1
==> cd ~/public_html/example.com

user1@www2: /usr/home/user1/public_html/example.com
==> wp core download
Downloading WordPress 5.0.2 (en_US)...
md5 hash verified: 5c64f31e0a034678a618f4931b24c911
Success: WordPress downloaded.

That was easy! Next, we will generate the WordPress config file and lock it down:

user1@www2: /usr/home/user1/public_html/example.com
==> wp config create --dbhost=dbXYZ.pair.com --dbname=user1_wpdb --dbuser=user1 --dbpass='xxxyyyzzz' --dbprefix=xy_ --dbcharset=utf8mb4
Success: Generated 'wp-config.php' file.

user1@www2: /usr/home/user1/public_html/example.com
==> chmod 600 wp-config.php

To execute the above wp command, you have to know your pair Networks database credentials. You may want to select a dbprefix name. The chmod command ensures that the wp-config.php file is only readable and writeable by your username.

Ok, now we’re ready to run the wp install command.

user1@www2: /usr/home/user1/public_html/example.com
==> wp core install --url=https://example.com --title="Mysite" --admin_user=myadmin --admin_password='mysite-password' --admin_email="myadmin@example.com"
Success: WordPress installed successfully.

That was easy too! Use “https” to start your URL if you have set up SSL; otherwise, use “http”. Don’t use “admin” for your admin username. Set a very secure admin user password. If your email is working, you should also receive a confirmation email from your WordPress site that it was successfully set up. You can then click on the link in your email and bring up your new WordPress site. Also, in the same confirmation email, you can click on your “wp-login” link and log into your site using your admin Username and Password from the above wp command.

Hopefully, that all worked for you and you now have a WordPress website installed on your pair Networks shared host. Now, you can start building your website, which includes setting up a basic set of plugins–for example–adding a contact form, and, of course, adding content.

Setting up a basic set of plugins is another post.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.