Introduction to WP-CLI for WordPress

June 29, 2017

If you are a WordPress developer and use the command line, we have great news for you. WP-CLI is a command line tool for administering WordPress sites and it is pre-installed and available for use on Rochen’s servers.

WP-CLI enables you to administer various areas of your WordPress site without touching the WordPress administration dashboard and web server. With most hosts you’d have to install and manage WP-CLI on the server yourself but with Rochen’s optimized WordPress hosting plans we take care of this burden for you.

Using WP-CLI, you can manage your WordPress installations and upgrades. You can edit configuration files, and work with your site’s database. You can also handle administrative tasks such as posting, approving or deleting comments, plus uploading or processing media files. WP-CLI can really speed up many repetitive WordPress administration tasks.

As a Rochen customer, you already have WP-CLI available with any WordPress install on our servers. To start working with the WP-CLI tool, you need to enable SSH from the My Rochen customer portal for the relevant account, open an SSH client on your computer, and connect to your Rochen account using SSH.

If you run Mac or Linux, you already have an SSH client pre-installed with your operating system. If you are on Windows, we suggest you download and install an SSH client such as Putty.

For added security, by default, all Rochen hosting accounts have SSH disabled but you can enable it from within the My Rochen customer portal with just four clicks.

To enable SSH –

  • Login to the My Rochen customer portal
  • On the left menu click “Managed Services”, then click “Shared Hosting” and then click on the primary domain name for your account
  • Under the relevant section (1) of the WordPress site find “SSH” (2), click “Enable” (3) and then click “OK” (4) within the popup box:

Now you can connect using SSH to the relevant Rochen account. Type the following command in your SSH client terminal window and press the “Enter” key:

ssh <your_hosting_user_name>@your_server_IP_address:

When prompted, enter the password associated with the Rochen hosting account (keep in mind that you will not see any activity in your command line prompt as you type in your password), press the “Enter” key again and you’re connected. You are now set to start managing your WordPress site with the WP-CLI command line tool.

Let’s assume that you want to install and activate the latest version of the WordPress plugin called PublishPress. Type this command:

wp plugin install publishpress –activate

Now, when you visit your WordPress administrator dashboard, you will see the PublishPress plugin is installed and activated:

Let’s use another example. Imagine that you want to delete all comments marked as “spam”. If you have a few thousands of comments or more, it will be very difficult to do this using the administrator dashboard.

WP-CLI comes to the rescue. To do the job, type in the following command:

wp comment delete $(wp comment list –status=spam –format=ids)

To see all of the commands built into WP-CLI, please visit the commands reference page on the official website.

Although learning WP-CLI commands can take some time, once you get to grips with them, your WordPress day-to-day management will become much easier.

Let’s have a look at some of the benefits of WP-CLI.

Reduced Web Server Load

Your WordPress administrator dashboard is browser-based. Every time you run a task via your WordPress dashboard, you create a load on the web server. If you run the same tasks via WP-CLI, you will bypass the web server and save systems resources.

Some of the WordPress administrative tasks, such as processing multiple images or videos, for example, can take significant resources. If you’re running a large task then this could hit web server timeout limits.

Launch the same task using WP-CLI and your images or video files processing will run without interruption as long as it takes. There will be no timeouts while the task runs smoothly in the background.

Increased Productivity

Use WP-CLI and watch your productivity soar. Think of a scenario where you need to run the same WordPress task repetitively. For example, if you have multiple WordPress sites installed and would like to update all of them.

Or maybe you would like to perform two (or more) tasks concurrently. For example, you may want to update and activate all of your WordPress plugins at the same time. WP-CLI comes in very handy in such use cases.

Improved Security

It takes a lot of lines of code to create graphical user interfaces, such as the WordPress dashboard. The more code an application has, the more prone to bugs and security issues it is. In contrast, WP-CLI is a set of much smaller command line tools, which makes them much more secure. Instead of installing dozens of management plugins, you can use WP-CLI to perform the same tasks.

Conclusion

It may take you time to learn WP-CLI commands to run your day-to-day WordPress tasks, but it is well worth it.

In our next few blog posts, we’ll show you how to use WP-CLI commands to run specific WordPress administration tasks.

TOPICS

Web Hosting

TAGS

This article was published on June 29, 2017 by Rochen.

Need help with your order? Email Sales or call 1-888-706-HOST