Upgrading WordPress plugins on Lightsail with wp-cli
How we update WordPress plugins on a Lightsail/Bitnami install using wp-cli
We recently moved a WordPress website away from managed hosting and onto Lightsail. Amongst the changes is a new reliance on wp-cli, which I’d never used before. This post will share the steps I take to upgrade WordPress plugins using Lightsail and wp-cli.
We used the Bitnami WordPress setup, which uses wp-cli for most things. I’m sure I could start changing stuff to allow it to work the way I was more used to it working, but this seemed like an excellent learning opportunity.
wp-cli is a command line interface tool that lets you interact with WordPress; it means you can type stuff into your terminal, and WordPress will respond.
To access it, you need to SSH into your Lightsail instance.
I almost always add some details to my
~/.ssh/config file to make this easier.
Host site HostName 188.8.131.52 User ssh_user IdentityFile ~/.ssh/my_key.pem
Having config like this allows me to type
ssh site, and it will connect me to
184.108.40.206 with the user
ssh_user and verify my identity with the file stored in
You can get all of this information by logging into your Lightsail account. The HostName will be the IP address they give you, the user will be clearly marked, and you can download the appropriate keys from Amazon.
The way Bitnami lays things out confuses me a bit; I hope I will eventually understand it better. Still, luckily wp-cli can be run from any directory on the host machine.
You can test this by calling
wp --info, and if you see the correct relevant looking output, you’re good!
I like to keep all plugins up to date, but I like to see what is potentially going to change, so the first command I run is;
wp plugin update --all --dry-run
--dry-run will tell me all the plugins that are about to be updated, their current version, and their new version.
If you’re happy with everything, remove
--dry-run and rerun the command;
wp plugin update --all
Running this command will;
- enable maintenance mode
- download the new updates
- install them
- disable maintenance mode
If there is a plugin you’d rather not update, you can pass its name into an exclude flag like so;
wp plugin update --all --exclude=plugin-to-ignore
I usually don’t like to jump up to a new major version of a plugin without reading more about it; you can tell it not to update past a patch or minor number by adding either
If for some reason, a root user created your WordPress setup (ours was), you will probably need to pass the flag
--allow-root and run the command with
sudo in front.
sudo wp plugin update --all --allow-root.
If you don’t do this, it will appear to work, but the updated files will have the wrong user attributed with them, and WordPress will likely crash out.