It is often very useful to manage your WordPress site with command line tools. WP-CLI is created just for that purpose. You first need to connect to the server via SSH to use WP-CLI tools. Read here more about how to connect to your site with SSH.
What Is WP-CLI?
An essential part of Seravo's WordPress platform are good developer tools, from which one of the most relevant is the WP-CLI command line tool. With WP-CLI you can update expansions, configure multisite installations and do much more, without using a web browser. The fundamental idea is that the WordPress site can be managed completely from the command line.
Traditionally as an admin you can manage the website from the Control Panel, but WP-CLI will make managing the site faster and easier. Running updates, creating backups, and other regular admin tasks are quickly executed from the command line with WP-CLI commands.
The WP-CLI version 2.12 is available for all Seravo customers, and with new orders it comes automatically. In this version the structure of the tool is updated so that it guarantees fast execution times for its user. Also the usability and reliability of the tool rose to a new level with the update compared to the earlier versions.
Most Commonly Used WP-CLI Commands
List all installed plugins:
wp plugin list
# Prints all plugins...
You can deactivate any plugin like this:
wp plugin deactivate awesome-plugin
Plugin 'awesome-plugin' deactivated.
Success: Deactivated 1 of 1 plugins.
Activate another theme:
wp theme activate twentynineteen
Success: Switched to 'Twenty Nineteen' theme.
Print all users on your site:
wp user list
Prints all users...
Print all admin users on your site:
wp user list --role=administrator Prints all admin users...
Change password for user with user email address:
wp user update [email protected] --user_pass=NewPassword
Success: Updated user 7.
Sometimes you might need to replace some changed info (email address for example) to new one to your sites database. You can use this search-replace command:
wp search-replace '[email protected]' '[email protected]' --all-tables
# tip: you can test your command by adding this to the end --dry-run
Custom WP-CLI Commands at Seravo
We have created some of our own WP-CLI commands for our servers. Here are some of the most commonly used ones:
Backups
We take backups of all our sites every night. But it is often very useful to take a backup when you start modifying your site. You can take a backup with this command:
wp-backup
...
--> Backup completed
Successfully backed up 323 MB of data.
Site Testing
Tests can be run from command line:
wp-test
...
Time: 9.76 seconds, Memory: 12.00MB
I: Finished running wp-test-ng
Emptying Cache
After modifying your site it might be necessary to empty cache. You can do it like this:
wp-purge-cache
--> Purging Nginx page cache...
Cache purged successfully for example_12345.
--> Purging WordPress object cache...
Success: The cache was flushed.
--> Flush WordPress rewrites...
Success: Rewrite rules flushed.
--> Flush the entire Redis cache (includes Nginx PageSpeed cache etc)...
--> Success
Developer Documentation
Read more about Seravo custom WP-CLI commands from our developer documentation. Other useful links: wp-cli.org and WordPress developer documentation.