How WP-CLI Can Make Your Life Easier (Video)

Recently we had the pleasure of hosting a webinar with Alain Schlesser, the lead developer of the WP-CLI project, the command line interface for WordPress. Nearly 1300 people attended and we had a blast fielding questions and seeing our clients engage with us live. Even if you have missed the live stream, it is not too late to learn how to do some of the most popular things with WP-CLI, like automating backups, troubleshooting website errors, performing a search & replace in your database, cleaning up spam comments, resetting your passwords, and more. All you have to do is watch the webinar video below.

You can find a list of all commands Alain used in the webinar here

A lot of users’ questions were answered by Alain during the live webinar. However there were some that we couldn’t get to and we’ve added them below along with the answers.

Q: Are changes made by WP-CLI on a development site carried forward when the site is migrated and made live?
A:
Changes made by WP-CLI are applied to the WordPress installation which resides in the folder you’re in. Alternatively, you can specify a ‘–path’ to the installation you want to work with. If you execute commands to your live site, e.g. in your public_html folder, they will immediately apply to it.

Q: What can WP-CLI do that I can’t do just as easily by running SQL against the tables?
A: Using WP-CLI is much easier, faster, and most importantly safer than running SQL directly. Plus, it takes care of things like serialization, lowering the chance of creating errors. 

Q: Is it possible for me to transfer WooCommerce orders between multiple sites creating a multisite setup using WP-CLI?
A: There is no default command that can do that. There are custom commands and workarounds but we recommend you use the export functionality of WooCommerce in the background for this purpose.

Q: How could we force a WordPress site to use a remote database? For example, on SiteGround, with content and database, we wanted the site to use a remote database for its wp-config on Digital Ocean or some other server, can it be done with WP-CLI using SSH?
A: Yes, this is doable but you don’t need WP-CLI for this task. All you need to do is edit your wp-config.php file and replace the MySQL hostname, port, user, password and db name configuration lines with the ones from your other server. Once WordPress links to it, WP-CLI will work with the remote database just fine.

Q: Can we do content and db backups to a remote server on a schedule?
A: Yes, you could do that. You can set up a cron job from your hosting account control panel to call wp db export. Then, you can upload that file to a remote server. This, however, would require another bash script depending on the access you have to the remote server and the level of authentication it requires.

Q: Can you install a theme from GitHub?
A:
Yes, the ‘wp theme’ command accepts URLs as a parameter.

Q: Is there any way to force check for updates like the admin UI does? So many times WP-CLI won’t show updates when there are updates ready.
A:
That’s a great suggestion for a new command! I recommend joining the #cli channel in the https://make.wordpress.org Slack!

Q: Is there a way to have a pre-configured wp installation package with theme and theme settings, plugins, and SEO settings in place so I can quickly create websites in my cPanel?
A:
Yes, you can do a simple script as the one we showed in the beginning of the webinar that installs everything you need and uses the ‘wp option update’ command to configure your SEO and other plugins.

Q: When installing WP-CLI with a local environment, would the install be in the root of the computer (global) or the root of the site?
A:
Where you install it locally depends solely on your personal preferences. 

Q: Can I only use WP-CLI if the server or host accepts ssh?
A:
Yes, it’s a command line interface which requires shell access.

Q: What about reversing mistakes . . . is there a reversion command?
A:
WP-CLI doesn’t track the changes you make. This said, if you back up before making changes, you can easily restore from that backup using the ‘wp db export’ and ‘wp db  import’ commands.

Q: Does reset-password include a method to display the new password in STDOUT? Often the email inbox is inaccessible causing the loss of the password in the first place.
A: No, but you can reset it directly using ‘wp user update admin –user_pass=password’ 

Q: I recently had a local development of a plugin that created a custom role on activation, e.g. “basic_member”. What I wanted to do is change that role to “starter_member”. I could easily search and replace that in my plugin files but I couldn’t do that with WP-CLI, which I thought would be easily enough to do. Is there a reason why you cannot do this?
A: Actually, you can – just use the ‘wp user update username –role=starter_member’ command replacing ‘username’  with your actual username.

Q: Can WP-CLI be used to clone a site?
A: Yes, you can do an export of your database and zip all your files and folders into an archive. Then, import your SQL file into a new database, restore files and you have a clone of that site!

Q: Is there a command to remove a site?
A: Your site consists of database and files. You can simply ‘wp db drop’ and then delete all the files and folders in that directory.

Q: This is all very new for me. As I’m learning, how easy would it be to break the site from WP-CLI?
A: It’s as easy as it is to break it from your admin panel. WP-CLI is powerful, but if you’re careful with your actions you shouldn’t break your site.

Q: How do I stop a media download while running a wp import command: (wp import wordpress.2019-07-09.xml –authors=create)
A: You can just terminate the command execution with Ctrl+C or Command+C.

Access email sent!

Sign Up For
More Awesome Content!

Subscribe to receive our monthly newsletters with the latest helpful content and offers from SiteGround.

Thanks!

Please check your email to confirm your subscription.

Hristo Pandjarov

Product Innovation Director

Enthusiastic about all Open Source applications you can think of, but mostly about WordPress. Add a pinch of love for web design, new technologies, search engine optimisation and you are pretty much there!

Comments ( 9 )

author avatar

Richard Rosario

Jul 15, 2019

It's nice that you posted the video of the webinar.. I am watching it now.. great stuff.. I have been working with wordpress for years but having a CLI is on another level.. props to your team for hosting this.. great job.

Reply
author avatar

Ian

Jul 16, 2019

Got a lot out of this. Hope SiteGround keeps coming through with video content. One thing I have struggled to do is create my alias as the ssh path looks completely different to mine and I'm not sure of structure of that SSH path or what the operators are of that SSH path he used to create the alias.

Reply
author avatar

Alain Schlesser

Jul 16, 2019

Hey Ian, The structure of the SSH path is documented here: https://make.wordpress.org/cli/handbook/running-commands-remotely/#using-an-ssh-connection So it is this format: `[<scheme>][<user>@]<host>[:<port>][<path>]` Let's compare it to the string I used in the webinar: `--set-ssh=u126-wjdeyjeuu9mh@gnldm1001.siteground.biz:18765/home/u126-wjdeyjeuu9mh/www/hristop13.sg-host.com/public_html` We'll have: `user => u126-wjdeyjeuu9mh` `host => gnldm1001.siteground.biz` `port => 18765` `path`=> /home/u126-wjdeyjeuu9mh/www/hristop13.sg-host.com/public_html` Hope that helps, Alain

Reply
author avatar

Daniel Gutiérrez

Jul 16, 2019

Hello Alain, I just wanted to show my grattitude because WP has saved me tons of time migrating a lot of sites, updating wp where the host is slow, and so many more things. Best wishes from Mexico.

Reply
author avatar

Linda

Aug 03, 2019

I will def. listen the complete video, but as i noticed my question does not relate to any faq here on the page.. I will start typing already :D I used WP CLI to update the WP database and that worked perfectly. Now I have a lot of trouble uploading a bulk media folder and a large products.csv for woocommerce. Either with FTP or other plugins I cannot seem to get it to work. Would WP CLI be an option, and if so, what are the specific commands?

Reply
author avatar

Hristo Pandjarov Siteground Team

Aug 05, 2019

I am afraid that WooCommerce doesn’t have import functionality added to the set of commands available through WP-CLI. That’s a very common problem with WooCommerce that doesn’t have a straight-forward solution. Something that’s been working for me doing this is to split the exports of products into categories, i.e one file for shoes, one for shirts, one for caps. This way, you will reduce the size of the files that you need to import later on. This, however, works until you reach certain size of a single category. Due to the lack of import in batches functionality in such cases I download the whole database locally, set infinite timeouts on my computer, leave the import to work for whatever time necessary and then export the product tables. Once that’s done, I upload them via FTP to the account, delete the existing product tables and import them using SSH with mysql -uUSER -pPASS dbname < products-imported.sql. Ideally, they will develop a WP-CLI command to do that and you would be able to simply upload the CSV via FTP and run it but until then workarounds must be used after certain size.

Reply
author avatar

Ian Douglas

Oct 04, 2019

Great overview of a fabulous tool. Thank you Alain Schlesser for all your dedication and hard work on WP CLI, and WordPress in general.

Reply
author avatar

Greg

Nov 03, 2019

Thanks Alain for introducing me to this command system and all your work to keep the Wordpress backbone fast and strong. Look forward to more of your videos!

Reply
author avatar

Matt

Jan 16, 2020

Thanks to both of you for taking the time to sharing this awesome CLI with us! I just watched the YouTube webinar and was very impressed with some of the things you can do with it. As an active developer of many WordPress plugins and websites for several clients, I can and will definitely start using WP-CLI and it all thanks to you guys. Cheers, Matt

Reply

Start discussion