Title: Managing Multiple WP Sites with WP-Cli
Last modified: March 11, 2020

---

# Managing Multiple WP Sites with WP-Cli

 *  [djtech2k](https://wordpress.org/support/users/djtech2k/)
 * (@djtech2k)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/)
 * I am fairly new to WP. I am trying to run the php compat checker but keep hitting
   timeouts, so I read to try the WP-Cli to do it.
 * So I have a server and I host multiple WP sites going across multiple domains.
   I see the install of WP-Cli seems to be one per-server so I am trying to understand
   how it works. For example, can I use WP-Cli to manage each individual WP site?
   Otherwise how would it know which site I am issuing the command towards.
 * Maybe I am overlooking something, but I am trying to figure out how will the 
   Cli know which site to make changes to.
 * Thanks in advance.
    -  This topic was modified 6 years, 3 months ago by [djtech2k](https://wordpress.org/support/users/djtech2k/).
    -  This topic was modified 6 years, 3 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Everything else WordPress
      topic

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/#post-12529529)
 * If you really like wp-cli, see [https://make.wordpress.org/cli/handbook/running-commands-remotely/](https://make.wordpress.org/cli/handbook/running-commands-remotely/)
 * I use [MainWP](https://wordpress.org/plugins/mainwp/) to manage a bunch of sites.
 *  [phillcoxon](https://wordpress.org/support/users/phillcoxon/)
 * (@phillcoxon)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/#post-12529747)
 * Hi [@djtech2k](https://wordpress.org/support/users/djtech2k/),
 * Yes, you can use wp-cli to manage multiple sites on a server. It will depend 
   on how your hosting server is set up. For example, many hosting environments 
   run each website user under their own user account so once you ssh into the server
   as the root user you can use su to become that user and run wp-cli commands from
   the web root folder for each individual website.
 * For example:
 * su username
    cd ~/username/public_html #path will very depending on hosting server
   setup wp plugin update wp plugin install phpcompat –activate wp phpcompat 7.2–
   scan=active exit #to exit the sudo session and return to the root login
 * If you don’t run your own hosting server you may be able to get ssh access on
   a per account basis and it will be the same process as above except that you 
   will ssh into the server directly as the server.
 * For example:
 * ssh -p2222 [username@myhostingaccount.com](https://wordpress.org/support/topic/wp-cli-question-2/username@myhostingaccount.com?output_format=md)#
   where 2222 is the SSH port for the server
    cd ~/username/public_html #path will
   very depending on hosting server setup wp plugin update wp plugin install phpcompat–
   activate wp phpcompat 7.2 –scan=active exit #log out of the ssh session
 * It’s also possible to run wp-cli commands locally that are applied on remote 
   servers as indicated by Steve’s response above.
 * wp-cli is amazing. Once you start using it regularly you’ll wonder how you ever
   got by without it 😀
 * Hope that helps!
 *  [phillcoxon](https://wordpress.org/support/users/phillcoxon/)
 * (@phillcoxon)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/#post-12529840)
 * Hi [@djtech2k](https://wordpress.org/support/users/djtech2k/),
 * I wanted to post one additional update. If you are new to SSH access and using
   shell command I would caution you to be careful while you learn to use command
   line access.
 * This is especially important if you have root access to a server where a single
   mistyped command can destroy a server or delete files with no ability to undelete(
   must be restored from backups).
 * In most hosting accounts where we are given SSH access on a per user or website
   basis the worst we can do is damage our own hosting account files.
 * Either way, SSH access is extremely useful and powerful but always requires careful
   use and attention, particularly when deleting files and changing permissions.
 * I’d recommend setting up a cheap hosting account with ssh access (not a production
   website) and spend some time learning and testing both shell commands and wp-
   cli before using on a production site.
 * As always, ensuring you have great backup strategies in place is very important
   😀
 *  Thread Starter [djtech2k](https://wordpress.org/support/users/djtech2k/)
 * (@djtech2k)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/#post-12531832)
 * Thanks for the replies.
 * I will check out some of these procedures later today. My goal is not around 
   mass management of WP because I only have a few sites that I manage. My main 
   question was because the install docs for WP-Cli talk about installing and running
   a command, but I could not understand how would WP-Cli know which WP site to 
   execute the command against.
 * In my example, I run a server that has cPanel. I have a few different sites/domains
   and some of WP site(s). So if I installed WP-Cli, how would I differentiate which
   site to manage. That was my main issue. I do have root access and I am familiar
   with SSH, so running by command-line is no problem for me.
 *  [phillcoxon](https://wordpress.org/support/users/phillcoxon/)
 * (@phillcoxon)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/#post-12538477)
 * Hi [@djtech2k](https://wordpress.org/support/users/djtech2k/),
 * On a cPanel/WHM server you can log in as root via ssh.
    From there if you know
   the account username of the website you wish to manage with wp-cli you can simply
   type:
 * `su username`
 * If you’re not sure what the usernames are you can run:
 * `ls -l /home`
 * …which will list the usernames.
 * So the full process will be something like:
 *     ```
       su username
       cd /home/username/public_html/
       wp plugin list #and whatever other commands you want to run
       ```
   
 * By FAR one of the most value wp-cli commands you can use is the database backup
   command. It makes it easy to test changes or updates and have the ability to 
   roll back in seconds.
 * `wp db export 2020-03-12.website.db.sql`
 * …would export the current database with the above filename, for example. You 
   can then test changes and if you want to roll back you can do so in seconds using:
 *  `wp db import 2020-03-12.website.db.sql`
 * Always be sure not to leave sql databases lying around anywhere in your web accessible
   path. on cPanel/WHM servers I often have additional external storage connected
   under /backup and have scripts that will back up sites databases and store them
   temporarily – /backup/websitename/2020-03-12/database_name.1422.sql – for example(
   where 1422 is the time in 24 hour format).
 * There’s so many possibilities to use bash scripts with wp-cli to create useful
   automation.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Managing Multiple WP Sites with WP-Cli’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [phillcoxon](https://wordpress.org/support/users/phillcoxon/)
 * Last activity: [6 years, 3 months ago](https://wordpress.org/support/topic/wp-cli-question-2/#post-12538477)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
