If you are familiar with WordPress you know that there are things that need to be done on the regular basis. As a business owner, a blogger, or even developer, you’ll find yourself repeating the same steps over and over again.
The graphical interface that WordPress presents is absolutely a great place to start for people that use WordPress as a regular administrator of content. In other words if your job is to admin content for one website and you don’t consider yourself a technical person, then the GUI is perfect for you.
But what happens if you are becoming more technical and now instead of just managing the content you also have to update plugins and the core? How about running backups on demand for five websites? Now, the thought of having to go to each of those five websites one by one and doing the tasks becomes overwhelming for most people.
Welcome to WP-CLI
WP-CLI or WordPress in the Command Line is a project that allows administrators to manage WP from a command line. There is no user interface, instead just a prompt. Nothing loads, it just simply waits for commands and executes them.
WP-CLI allows us to create a database backup or create new users or run absolutely any query against the database all from the comfort of… the root directory of the WordPress installation. Wait a second. Why would you go into all that trouble if you still have to log into the root directory of each one of your websites?
Welcome to Aliases in WP-CLI
Aliases are basically a simple notation that allows you to name your sites with a short name. That short name is called an alias. The alias then is used to call WP-CLI commands from the comfort of your local computer.
In essence, what it does is that it saves the ssh configuration properties for each website and connect to them on-demand in order to run the commands.
Do you need to update 100 websites to the latest version of WordPress? No problem. Simply run a backup command on all aliases, and then run the update command – and you are done.
What is the notation to create the aliases?
In the following lines you’ll find what you need to add to your config.yml file in order to create the aliases. Where is your config.yml file? Simply go to where you installed wp-cli in your machine and under the folder you should find the config.yml file. Open the file and add your aliases as seen below:
# An alias can include 'user', 'url', 'path', 'ssh', or 'http' @staging: ssh: email@example.com user: wpcli path: /srv/www/staging.wp-cli.org @production: ssh: firstname.lastname@example.org:2222 user: wpcli path: /srv/www/wp-cli.org
And that’s it. As long as you have your ssh keys in place and you are authorized to connect via SSH to those servers, you should be ready to go.
Grouping Aliases for an even easier setup!
Let’s say that you want to execute a command across all of your clients. For example updating the core across all of them. That’s what grouping is for. To group aliases all you have to do is add the aliases to the group by adding to the yaml file:
# Add group of aliases. @clientsa - @client_this - @client_another @clientsb - @client_that - @client_another_one
You may also call the adding to groups from WP-CLI by executing the following command:
# Add group of aliases. $ wp cli alias add @allclients --grouping=clientsa,clientsb Success: Added '@allclients' alias.
And finally, let’s say that you want to execute your command across all of the websites with a registered alias, regardless of their grouping. All you have to do is execute it against the @all alias.
And that’s it. That’s how you can use aliases to speed up your WordPress across multiple servers.