Using WP-CLI with InterServer shared hosting

WP-CLI is available on Linux Plans for InterServer shared hosting. It is not available on ASP.net plans.

To use WP-cli the installed location must be called. WP-CLI is installed at /opt/wp

This path can be called by scripts, or cron and of course SSH. To enable SSH on a shared hosting account please contact support.

WP-CLI can not run with suhosin, which is installed by default – so the first command to run is to set the path of PHP.

export PATH=/opt/cpanel/ea-php71/root/usr/bin:$PATH

Once done /opt/wp can be called. Start with the –info switch. For example

[wptest@webhosting2024 ~]$ export PATH=/opt/cpanel/ea-php71/root/usr/bin:$PATH
[wptest@webhosting2024 ~]$ cd public_html
[wptest@webhosting2024 public_html]$ /opt/wp --info
OS: Linux 3.10.0-714.10.2.lve1.5.17.el7.x86_64 #1 SMP Mon Apr 30 13:06:32 EDT 2018 x86_64
Shell: /bin/bash
PHP binary: /opt/cpanel/ea-php71/root/usr/bin/php
PHP version: 7.1.18
php.ini used: /opt/cpanel/ea-php71/root/etc/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /home/wptest/public_html
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.5.1

 

The first command sets the path to php to 7.1 with out suhosin. The second command moves into the public_html folder where WordPress is installed. Finally the last command runs wp-cli with the info switch. If nothing returns there is an error that will be displayed normally in the same folder under the file error_log.

WP cli has many options. It can verify checksums, update wordpress, plugins, themes, disable plugins and more.

Multiple commands can be placed on the same line. For example if you want to verify checksums, update plugins and themes

export PATH=/opt/cpanel/ea-php71/root/usr/bin:$PATH; /opt/wp core verify-checksums; /opt/wp core update; /opt/wp plugin update --all

 

The above sets the php path, verifies checksums, updates wordpress and updates plugins.

 

An example output would look like

 

Warning: File should not exist: wp-admin/error_log
Success: WordPress installation verifies against checksums.
Success: WordPress is up to date.
Enabling Maintenance mode...
Downloading update from https://downloads.wordpress.org/plugin/akismet.4.0.7.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Downloading update from https://downloads.wordpress.org/plugin/loginizer.1.4.0.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Disabling Maintenance mode...
+-----------+-------------+-------------+---------+
| name | old_version | new_version | status |
+-----------+-------------+-------------+---------+
| akismet | 4.0.3 | 4.0.7 | Updated |
| loginizer | 1.3.9 | 1.4.0 | Updated |
+-----------+-------------+-------------+---------+
Success: Updated 2 of 2 plugins.

Note: Warning: File should not exist: wp-admin/error_log Рthis file is not part of a wordpress install. In this case this is created by php. Should PHP files show that should not exist, they should be inspected as it could be hidden malware.

 

You can change themes as well. For example

 

[wptest@webhosting2024 public_html]$ /opt/wp theme list
+-----------------+----------+-----------+---------+
| name | status | update | version |
+-----------------+----------+-----------+---------+
| twentyfifteen | inactive | available | 1.9 |
| twentyseventeen | active | available | 1.5 |
| twentysixteen | inactive | available | 1.4 |
+-----------------+----------+-----------+---------+
[wptest@webhosting2024 public_html]$ /opt/wp theme activate twentysixteen
Success: Switched to 'Twenty Sixteen' theme.
[wptest@webhosting2024 public_html]$ /opt/wp theme list
+-----------------+----------+-----------+---------+
| name | status | update | version |
+-----------------+----------+-----------+---------+
| twentyfifteen | inactive | available | 1.9 |
| twentyseventeen | inactive | available | 1.5 |
| twentysixteen | active | available | 1.4 |
+-----------------+----------+-----------+---------+

Or update themes

[wptest@webhosting2024 public_html]$ /opt/wp theme update --all
Enabling Maintenance mode...
Downloading update from https://downloads.wordpress.org/theme/twentyfifteen.2.0.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the theme...
Theme updated successfully.
Downloading update from https://downloads.wordpress.org/theme/twentyseventeen.1.6.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the theme...
Theme updated successfully.
Downloading update from https://downloads.wordpress.org/theme/twentysixteen.1.5.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the theme...
Theme updated successfully.
Disabling Maintenance mode...
+-----------------+-------------+-------------+---------+
| name | old_version | new_version | status |
+-----------------+-------------+-------------+---------+
| twentyfifteen | 1.9 | 2.0 | Updated |
| twentyseventeen | 1.5 | 1.6 | Updated |
| twentysixteen | 1.4 | 1.5 | Updated |
+-----------------+-------------+-------------+---------+
Success: Updated 3 of 3 themes.

 

WP-CLI is very powerful and offers many different sub commands

 

SUBCOMMANDS

cache Adds, removes, fetches, and flushes the WP Object Cache object.
cap Adds, removes, and lists capabilities of a user role.
cli Review current WP-CLI info, check for updates, or see defined aliases.
comment Creates, updates, deletes, and moderates comments.
config Generates and reads the wp-config.php file.
core Downloads, installs, updates, and manages a WordPress installation.
cron Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
db Performs basic database operations using credentials stored in wp-config.php.
embed Inspects oEmbed providers, clears embed cache, and more.
eval Executes arbitrary PHP code.
eval-file Loads and executes a PHP file.
export Exports WordPress content to a WXR file.
help Get help on WP-CLI, or on a specific command.
import Imports content from a given WXR file.
language Installs, activates, and manages language packs.
media Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
menu Lists, creates, assigns, and deletes the active theme's navigation menus.
network Perform network-wide operations.
option Retrieves and sets site options, including plugin and WordPress settings.
package Lists, installs, and removes WP-CLI packages.
plugin Manages plugins, including installs, activations, and updates.
post Manages posts, content, and meta.
post-type Retrieves details on the site's registered post types.
rewrite Lists or flushes the site's rewrite rules, updates the permalink structure.
role Manages user roles, including creating new roles and resetting to defaults.
scaffold Generates code for post types, taxonomies, plugins, child themes, etc.
search-replace Searches/replaces strings in the database.
server Launches PHP's built-in web server for a specific WordPress installation.
shell Opens an interactive PHP console for running and testing PHP code.
sidebar Lists registered sidebars.
site Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation.
super-admin Lists, adds, or removes super admin users on a multisite installation.
taxonomy Retrieves information about registered taxonomies.
term Manages taxonomy terms and term meta, with create, delete, and list commands.
theme Manages themes, including installs, activations, and updates.
transient Adds, gets, and deletes entries in the WordPress Transient Cache.
user Manages users, along with their roles, capabilities, and meta.
widget Manages widgets, including adding and moving them within sidebars.

 

Enjoy