Skip to content
Home Β» Blog Β» Installing WP-CLI on shared hosting

Installing WP-CLI on shared hosting

WordPress Command-Line Utility, or WP-CLI for short, is an advanced utility for power users who wish to rapidly manage and deploy their WordPress sites using bash/SSH.

Are you managing multiple WordPress websites

Have ever logged in to your client’s site just for the sake of Core WordPress Update or Plugin/Theme update?

Let us 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 log in 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 log in to your server via SSH and manage your WordPress installation quickly.

Why WP-CLI?

  • Serious Time Saver: No need to wait for the 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:Β The 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

Before moving forward 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. 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)
patilswapnilv@swapnil-desk:~$ 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/patilswapnilv
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.4.1
patilswapnilv@swapnil-desk:~$

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.

Example
β€œwp plugin list” will run as β€œphp wp-cli.phar plugin list”

Run alias command to assign alias
alias wp='~/wp-cli.phar'
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
source .bashrc
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.
patilswapnilv@swapnil-desk:~$ wp plugin list
+-------------------------+----------+--------+---------+
| name | status | update | version |
+-------------------------+----------+--------+---------+
| akismet | active | none | 4.0.1 |
| jetpack | active | none | 5.5.1 |
| syntaxhighlighter | active | none | 3.2.1 |
| wordpress-seo | active | none | 5.8 |
+-------------------------+----------+--------+---------+
patilswapnilv@swapnil-desk:~$

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

8 thoughts on “Installing WP-CLI on shared hosting”

  1. Pingback: What is WP-CLI and what can it do for you? - WILDE & wilde

  2. Awesome post! I have a question though.
    I’m running multiple websites on my shared hosting. So in my main directory I have one directory per wordpress installation. Do I have to add the Phar file to every sinlge wordpress directory? because right now when I go into a wordpress installation directory and try using wp-cli it doesn’t work. if I paste the wp-cli.phar into the directory it works.

    Thank you in advance

    Patrick

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.