The below steps can be run with root privileges on a server (VPS hosting). This feature is preinstalled with our VPS hosting accounts.
In this tutorial, you will learn to install and manage WordPress with the WP-CLI. WP-CLI offers a command line interface for WordPress. Users get the tools necessary to install and update plugins, create databases without using a web browser.
Prerequisites
- Unix-like environment (Linux, FreeBSD, Cygwin).
- PHP 5.4 or later
- WordPress 3.7 or later
Installation
Firstly, using SSH connect to your Server’s console. Then you can download the file wp-cli.phar using wget or curl.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Then, check if the downloaded Phar file is working.
php wp-cli.phar --info
Then you will need to set the permission to make the Phar file executable using the below command:
chmod +x wp-cli.phar
Now, move the file wp-cli.phar to a new directory named wp under /usr/local/bin. With this, you will be able to execute the WP-CLI commands by typing ‘wp’ at the start.
sudo mv wp-cli.phar /usr/local/bin/wp
Run wp –info to check if the installation was successful. If it was successful, you’ll see the output below:
Steps to Manage WordPress with WP-CLI
Let’s check some basic and useful WP-CLI commands.
WP-CLI Help System
WP-CLI offers a guide that is accessible by using “wp help“. This guide will give you a detailed info about a specific command. For example, if you want to learn in detail about config command, you can type in:
wp help config
Check the below sample output:
Steps to Manage Themes
Using the below command, list the themes present in your WordPress:
wp theme list
You will get the below output:
You can install a different theme, using the following command:
wp theme activate twentyseventeen
Steps to Manage Plugins
Similar to themes, you can also install and manage plugins using wp-cli.
Using the below command you can list the plugins that are already installed on your WP site.
wp plugins list
You can also search and install the plugins available from the command line. For example, use the command below to search for the plugin “Yoast SEO”.
wp plugin search yoast
You will get the below output:
Use the below command to install and activate the plugin:
wp plugin install wordpress-seo --activate
Steps to Update WordPress
To update WordPress from the command line, you will need to update the core WordPress files and the database to complete the update process.
Use the below command to update the WordPress core files:
wp core update
Then, use the below command to update the database:
wp core update-db
These are just the few commands that we have discussed in this guide. You will find more commands to manage your database, posts, and multi-sites.
Conclusion
Congratulations! Now you have learned to manage your WP installation from the command line.
Also Read:
The Complete Guide to Update Your WordPress