The WP CLI is a great tool you can use to quickly manage your WordPress site. You can use it directly from your terminal, or automated actions via a bash script.
Before you can start using the WP CLI, you need to install it on your server.
# Curl the installer
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
# Update the permissions and move it to the /usr/local/bin/
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Now that it’s installed, navigate to the root of your WordPress install. In most common installs of Nginx
or Apache2
you will find your installation in the following location.
cd /var/www/html
Note: WP CLI expects you to run commands as linux user and NOT root, if you do run the WP CLI as root you will need to add the following to each command you --allow-root
Let’s start by installing and activating a plugin
wp plugin install contact-form-7 --activate
Let’s say you want to update only a single plugin
wp plugin update contact-form-7
Let’s update all your plugins
wp plugin update --all
Let’s say you want to update all your plugins expect one
wp plugin update --all --exclude=contact-form-7
Let’s update your WordPress theme
wp theme update twentytwentyfour
Let’s update all your WordPress themes
wp theme update --all
Let’s update the WordPress core
wp core update
Let’s do a database backup. You can set the location of the backup, be sure to NOT store database backup in the root of your WordPress install.
wp db export ../backup.sql
Let’s do a database import
wp db import ../backup.sql
These are just a small sample of the vast amount of functions the WP CLI can do. You can find a full list of commands here.
Next Step:
You can run all these commands from a bash script and set up any task scheduler to run them for you. Leave a command if you want to learn how to set that up.