Are you managing multiple WordPress websites on daily basis?
Have ever logged in to your clients site just for the sake of Core WordPress Update or Plugin/Theme Update ?
Lets assume WordPress has released a new update and you have to update all themes and plugins of 10 different WordPress websites,
every time you’ve to login to the dashboard go to the updates page and select updates manually .
the above process is quite time-consuming, So in order to manage multiple WordPress websites in a quick way you can use WP-CLI
What is WP-CLI?
WP-CLI is Command Line interface based WordPress site management tool used to manage WordPress websites via SSH.
Using WP-CLI you can easily manage your websites without logging in, no need to remember your WordPress Login credentials. Just login to your server via SSH and manage your WordPress installation quickly.
- Serious Time Saver: No need to wait for page to load, No need to remember site passwords, You can just enter few commands and your work will be done in few seconds as simple as that.
- Supported & used by top Hosting Providers: Overall WP-CLI project is backed by Hosting Giants like BlueHost, Automattic, DreamHost, WPEngine & SiteGround. BlueHost has confirmed that they are using WP-CLI to upgrade more than 2 Million websites. According to a report out of 2 million websites 99% of websites were upgraded successfully.
- Easy to use: If too many options on GUI confuses you then WP-CLI is for you. As it is CLI based tool there is no huge list of drop down links or tons of buttons which helps you to navigate you from one page to other. Command line interface is pretty simple , Enter a correct command it executes properly and gives a output.
- No Passwords: Yes no need to remember login username and password for every website you manage. Just login to your server via SSH and let WP-CLI handle rest of the things. using WP-CLI you can handle each WordPress installation hosted on your server.
- Love for Terminal : If the geek inside you loves working with Dark terminal window then WP-CLI is for you.
Basic Requirements of WP-CLI
- SSH Access
- SSH Client (PuTTy)
Even before downloading SSH client make sure your hosting provider has enabled SSH access for your account. If not then request your hosting provider to enable SSH for your account.
Installing WP-CLI via SSH
1. Configuring SSH Client (PuTTy)
Open you PuTTy terminal client. Enter your server IP Address and Port attach your PPK (Public Private Key) file.
Navigate to SSH > Auth (Click on Browse to attach .PPK file)
Hit “Open” Button to start connection.
2. Login to server via SSH
Enter your username and password to access server via SSH.
After successful login enter “pwd” command to know your current directory.
Output should be /home/username
[username@server ~]$ pwd /home/username
3. Download Setup file
To install WP-CLI you must download setup file to our directory.
WP-CLI is open source project maintained by open source community
Latest version of wp-cli file is available as wp-cli.phar on WP-CLI GitHub repository.
Now you have to Download wp-cli.phar file to our current directory.
To download that file you can use “curl” command.
(you can also use “wget” command to download files from remote server)
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
hit enter key to execute command.
4. Making file Executable
In Linux operating system you can’t execute a file directly like the way you execute files in Windows, here you have to set permission for that particular file and make it executable so that users can use execute those files and accomplish their task
Now you have to set permissions to wp-cli.phar file and make it executable.
chmod +x wp-cli.phar
chmod +x is a Unix system call which may change the access permissions to file system objects and makes that file executable.
5. Testing Execution
After assigning permissions lets check whether the file executes properly.
If the command doesn’t execute properly then you should delete current .phar file and Download a new file.
To Check whether file is Executing properly, Run “php wp-cli.phar –info” command to get PHP version details and WP-CLI version details.
php wp-cli.phar --info
(version details will be displayed in following manner)
[ratnesh@srv03 ~]$ php wp-cli.phar --info PHP binary: /opt/cpanel/ea-php56/root/usr/bin/php.cagefs PHP version: 7.0 php.ini used: /opt/cpanel/ea-php56/root/etc/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /home/ratnesh WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 1.4.1 [ratnesh@srv03 ~]$
6. Setting up Alias for commands
Now in order to execute WP-CLI commands you have to always mention “php wp-cli.phar” before command.
Like “php wp-cli.phar plugin list”
(this command will display all the plugins installed in current WordPress website)
Syntax is too long, you can trim it and make it more user-friendly by assigning alias in .bashrc file or move wp-cli.phar file to usr/bin/wp folder.
This is final step of WP-CLI installation which can be executed in two ways
- .bashrc file method
- moving .phar file to bin folder
6.1 Adding alias to .bashrc file
Adding Bash alias for WP-CLI (.bashrc file method)
Using alias you can trim long code “php wp-cli.phar” to a short one “wp“.
Basically alias helps us to create a short version of long commands
In .bashrc file you have to create an alias and assign “php wp-cli.phar” to “wp” so that whenever you run a command in short form in terminal but in backend it will run as long format.
“wp plugin list” will run as “php wp-cli.phar plugin list”
Run alias command to assign alias
This command tells the system that every time when users enters “wp” consider it as “wp-cli.phar“, an executable file which is present in home directory.
echo "alias wp='~/wp-cli.phar'" >> .bashrc
using echo you can output the required statement then “>>” will append it to .bashrc file
here you use source command to update bash initialization.
6.2 Moving WP-CLI.Phar to Bin folder
In shared hosting user don’t have root level permission to move file from home directory to system folders or edit system level file that is why use .bashrc file editing method.
If you are trying to install WP-CLI on Virtual Private Server or Dedicated server then you can move wp-cli.phar file to /usr/bin/wp folder
mv wp-cli.phar /usr/local/bin/wp or sudo mv wp-cli.phar /usr/local/bin/wp
This will move .phar file to bin folder and help us to use WP-CLI just by typing “wp“.
Test WP-CLI Commands
If you have completed all the above steps then run any WP-CLI command to check whether it is working properly.
Run “wp plugin list” command to check installed plugin status and plugin version.
[ratnesh@srv03 public_html]$ wp plugin list +-------------------------+----------+--------+---------+ | name | status | update | version | +-------------------------+----------+--------+---------+ | akismet | active | none | 4.0.1 | | backupbuddy | active | none | 22.214.171.124 | | custom-css-editor | inactive | none | 1.4.0 | | easy-affiliate-links | active | none | 2.5.0 | | hello | inactive | none | 1.6 | | jetpack | active | none | 5.5.1 | | rocket-maintenance-mode | active | none | 3.8.1 | | syntaxhighlighter | active | none | 3.2.1 | | wp-tab-widget | inactive | none | 1.2.7 | | wordpress-seo | active | none | 5.8 | +-------------------------+----------+--------+---------+ [ratnesh@srv03 public_html]$
If you can see similar output then WP-CLI is working perfectly.
Hope you’ve understood how WP-CLI is installed on shared hosting servers. If you are facing any difficulty while installing WP-CLI let me know in comments below.
This is a basic tutorial on WP-CLI installation. Now you’ve learned how WP-CLI makes WordPress site management easy. There are few hosting companies which provides WP-CLI by default for every WordPress installation. You can find list of Hosting providers who are supporting WP-CLI project.
Using WP-CLI you can install WordPress, install Themes, install Plugin, Comment Moderation, Write Posts, Add users etc. For every process there is a CLI command mentioned in WP-CLI commands cheat sheet.
WP-CLI is maintained by open source community and new commands are added with every new release.
For more info about WP-CLI Project you can visit WP-CLI.org