The WordPress Content Management System (CMS) is a very popular CMS used by millions of websites today. It powers over 25% of all Websites currently. There are a variety of uses, it can be used to easily organize, manage, and create content on the web and handle interactions with visitors and contributors. It currently is used to power various e-commerce websites as well as content websites popularly called blogs.

There are a lot of tools that come with the default WordPress installation which allows you to install and configure your WordPress website. There are a lot of options that come with the default WordPress installation. You can install themes, plugins and even add custom functionality to the Web interface of WordPress.

If you want a complete tutorial on installation WordPress and setting it up, you can follow the complete guide by 000webhost. They provide a very thorough approach on how to install and configure your WordPress installation using the Web interface.

In this tutorial, we will the install WordPress in a slightly different way. The approach we will be discussing today usually becomes useful when you have to install multiple instances of WordPress and you have to write a script to do so. We will be using a tool called wp-cli.

To start this tutorial, we will need to, first of all, make sure our Ubuntu server is up-to-date with the various packages and updates. We will start doing that by running the following command below. The command will basically install all the recent packages unto your Ubuntu box.

sudo apt-get update
sudo apt-get upgrade

Next, we will install the wp-cli tool which we will be using to install the WordPress. This a PHP binary file which is also known as a phar file. The Phar file is convenient and an easy way to group PHP several files into a single file. As such, a phar file or archive provides a way to distribute a complete PHP application in a single file and run it from that file without the need to extract it to disk.

To install this we will just run the command below:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

This basically uses curl to fetch and install the wp-cli plugin on the Ubuntu box. If you don’t have curl installed you have to make sure you have it installed by using the command apt-get install curl.

Next, we will make the wp-cli file a full executable, this allows you to run the phar file like a regular binary file on the Ubuntu box. To do this we will be using the Linux command called chmod. By typing chmod +x we essentially make the file executable, below is the complete command.

chmod +x wp-cli.phar

At this point in the post, we have successfully downloaded and made the wp-cli phar file fully executable. If you have any difficulty at this stage feel free to reach out to us in the comments below and we can help you troubleshoot any issues.

The next step here would be to make sure that the wp-cli command is accessible everywhere you are in the Ubuntu box. The way we have it now, the wp-cli is only available in the current folder, if you change directories using the cd command you will notice that wp-cli file is not accessible. You will get the command not found error message.

The way to make the wp-cli binary file globally accessible, we will have to add it to the global path of all binaries within Ubuntu box. This way, regardless of the directory we find ourselves in the wp-cli command will still work. To do this we use the Linux move command called mv and rename the binary file wp. This way, we can just type wp and it will execute the wp-cli phar file.

sudo mv wp-cli.phar /usr/local/bin/wp-cli.phar
cd /usr/local/bin
mv wp-cli.phar wp

Now we have successfully installed the WordPress-CLI component and we have made it globally accessible throughout our Ubuntu box. What this means is that you can just type the command wp and the Ubuntu command will run the wp-cli command. The next steps will be to use this command to install and configure a WordPress website.

To test the installation we can just type wp --info or just use ./wp-cli.phar --info if you didn’t want to move the binary file into the global application path. The output of the command show looks like the results below. It basically returns the values of PHP and WP-CLi you have installed on your system.

OS:	Linux 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64
Shell:	/bin/bash
PHP binary:	/usr/bin/php7.0
PHP version:	7.0.25-0ubuntu0.16.04.1
php.ini used:	/etc/php/7.0/cli/php.ini
WP-CLI root dir:	phar://wp-cli.phar
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/root
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version:	1.5.0

Installing WordPress using WP-CLI

In this section of the tutorial, we will be using the WP-CLI command to install WordPress on our Ubuntu box. The first thing we want to make sure is that you have created a database that will be used to run your WordPress website. We will be using the command-line client to create a new database. Log in to the MySQL server, replacing user with your MySQL username and create the database using the commands below:

mysql -u user -p
create database wordpress-cli-demo;
grant all on wordpress-cli-demo.* to 'user' identified by 'password';
quit

Next, we will be downloading the WordPress files by using the wp-cli command by using the following options with the command below:

wp core download

At this point, we want to create the config file which specifies the database settings we will be using on our website. The database name and password show match the one created in the command above.

wp core config --dbname=wordpress-cli-demo --dbuser=user --dbpass=password --dbhost=localhost --dbprefix=wp_

Once this has been successfully installed you then have to run the install by using the command below. The command below actually installs the WordPress site using the configuration you have provided.

wp core install --url="http://test-domain.com" --title="WP-CLI Test Demo" --admin_user="adminuser" --admin_password="password" --admin_email="[email protected]"

We hope you enjoyed reading this tutorial about how to install WordPress on Ubuntu using the WP-CLI command-line tool. Feel free to leave your comments, ideas and suggestions below. Additionally, you can join our mailing list to get receive updates on any new post.

How to Set-up and Install WordPress Using WP-CLI on Ubuntu 16.04 LTS
Rate this post

Join over 20,000 users and get our best content

Each week we send 1 email to 20,000 smart entrepreneurs just like you. Enter your email below to join the crew.

Thank you for subscribing.

Something went wrong.