Skip to main content

WordPress CLI

  • Create a new database for the WordPress installation. Note down the credentials you assign.
  • Connect to your web hosting via SSH using PuTTY or similar. A guide can be found in our article SSH Access via PuTTY.
Details

Looking specifically for how to set up a server-side cron job for WordPress? See our dedicated article WordPress Cron Job.

Installing WordPress via WP-CLI

First navigate to the main directory of your web hosting account and create a new folder there for your new WordPress instance:

cd htdocs
mkdir wpinstanz1

In our example, this is called wpinstanz1. Navigate into the newly created folder:

cd wpinstanz1

Time to download the WordPress installation files:

wp core download --locale=de_DE

For the formal German version, use --locale=de\_DE\_formal.

Once the process has completed successfully, you will receive the following message:

Downloading WordPress 4.9.4 (de_DE)...
md5 hash verified: e8e41d41fcdbda559e7a4c097e9bddea
Success: WordPress downloaded.

The next step is to prepare the installation. First, the wp_config.php file must be created and configured. The credentials of the database created earlier will be needed!

Use the following command format:

wp core config --dbname=DBNAME --dbuser=ssdXXX --dbpass=PASSWORD --locale=de_DE

Now we finalise our installation:

wp core install --url=[http://example.com](http://example.com) --title="Test installation via WP-CLI" \
--admin_user=MaxMustermann --admin_password=YourSecurePassword \
--admin_email=max@example.com

From now on, you can access your new WordPress installation via your domain.

Update

As with any CMS, it is essential to install WordPress updates as promptly as possible to maintain the security of the installation and the safety of visitors.

You can choose whether to install sub-versions, only the latest minor version, or a specific version.

Update to the latest version including sub-versions:

wp core update

Update to the latest minor version:

wp core update --minor

Update to a specific version:

wp core update --version=4.9.4

After an update, the database may also need to be updated:

wp core update-db

Managing Plugins

With WP-CLI you can manage all plugin operations — installation, activation, updating, etc. — from the console. This is particularly useful when the WordPress backend is no longer accessible. Plugins can be installed from the WordPress Repository as well as from other sources, for example commercial SEO packs.

Already installed plugins can be listed. The list includes information about the plugin status (activated or deactivated), the version and whether it is up to date:

wp plugin list

For a fresh WordPress installation, the list looks like this:

+---------+----------+--------+---------+
|  name   |  status  | update | version |
+---------+----------+--------+---------+
| akismet | inactive |   none |   4.0.2 |
| hello   | inactive |   none |   1.6   |
+---------+----------+--------+---------+

First, we want to install probably the most popular caching plugin, W3 Total Cache:

wp   plugin   install   w3-total-cache

The following example installs and activates a plugin with a single command:

wp   plugin   install   --activate   w3-total-cache

An example of installing from another source:

wp   install
https://ecample-com/plugin/seo-pro-pack-plugin.zip](https://ecample-com/plugin/seo-pro-pack-plugin.zip

Activate an already installed plugin:

wp   plugin   activate w3-total-cache

Deactivate an already installed plugin:

wp plugin   deactivate   w3-total-cache

Deactivate all plugins (this is helpful for troubleshooting in some cases):

wp   plugin deactivate --all

Delete a plugin:

wp   plugin   uninstall w3-total-cache

Again, two steps can be combined into one command:

wp   plugin   uninstall   --deactivat w3-total-cache

Update a plugin:

wp   plugin   update   w3-total-cache

Check all installed plugins for updates and install them:

wp plugin   update   --all

WP-CLI also allows you to search for a specific plugin in the WordPress repository, for example to find the slug of a plugin. In our example, we are searching for a security solution:

wp   plugin   search   security

This returns the following output:

 Success:  * Showing   10   of   4459 *  plugins.
 +---------------------------------+----------------------------------+--------+
 | name                            | slug                             | rating |
 +---------------------------------+----------------------------------+--------+
 | Wordfence Security - Fire       | wordfence                        |   96   |    
 | wall & Malware Scan             |                                  |        |  
 | All In One WP Security & Fi     | all-in-one-wp-security-and-firew |   96   |
 | rewall                          | all                              |        |  
 | Sucuri Security - Auditin       | sucuri-scanner                   |   90   |  
 | g, Malware Scanner and Security |                                  |        |   
 | Hardening                       |                                  |        |   
 | Cerber Security & Antispam      | wp-cerber                        |   100  |  
 | Shield Security for WordPress   | wp-simple-firewall               |   98   |  
 | iThemes Security (formerly Bett | better-wp-security               |   94   |
 | er WP Security)                 |                                  |        |  
 | Anti-Malware Security and Brute | gotmls                           |   98   |   
 | -Force Firewall                 |                                  |        |   
 | WP Security Audit Log           | wp-security-audit-log            |   94   |  
 | WP Hide & Security Enhancer     | wp-hide-security-enhancer        |   88   |  
 | BulletProof Security            | bulletproof-security             |   92   |
 +---------------------------------+----------------------------------+--------+

As you can see, we get the first 10 of 4459 plugins. To display the next page, use:

wp   plugin   search   security   --page=2

To increase the number of plugins per page to, for example, 50, use:

wp   plugin   search   security   --per-page=50

If you have any questions, please contact our Support.