How to set up a site and install WP via CLI - and where CLI documentation is

SYSTEM INFORMATION
OS type and version Ubuntu 22.04.5
Virtualmin version 2.303

I know enough bash scripting to cause trouble. I’ve got some scripts to help me automate some things, and now it’s time to tackle a script that:

  1. Allows me to create a new site, optionally as a child of an existing site
  2. Install WordPress and have it appear in the WP Workbench
  3. Install SSL from Let’s Encrypt
  4. (run some other wp-cli stuff as the user)

I’m pursuing this again because this thread mentions that the Workbench is exposed to CLI.

As far as I can tell, the documentation for CLI is here: Command Line API | Virtualmin — Open Source Web Hosting Control Panel

It’s really not very complete. But you can run virtualmin help to see a list of commands. I don’t see the Workbench related command.

So my primary question is: Where can I find a FULL set of documentation about CLI commands? Surely I’m just missing something. :slight_smile:

I have some of it - for example: create-domain | Virtualmin — Open Source Web Hosting Control Panel

But I’m missing something, I think.

If others have already written scripts to do this sort of thing, I wouldn’t mind taking a peek at any of it you’d like to share.

You don’t mention if you have virtualmin pro if you don’t
Buy virtualmin pro that is integrated with a nice ui
Which gets around it I guess, however as I don’t use wordpress this post maybe totally wrong

Apologies for not specifying, but I have Virtualmin Pro.

I think the WP Workbench is a Pro-only feature - at least, the last topic I read on it indiciated it was.

And thank you for mentioning the GUI, but I had hoped my message made it clear that I’m not trying to use the GUI. The entire point is to be able to write bash scripts for automation and voide the GUI, because the GUI - while nice - is not nearly as fast as CLI.

I would guess that the virtualmin api would allow you to script that, but someone else who is better placed could perhaps answer that

Yes. I am aware that the Virtualmin CLI has the functionality, because the thread I linked specifically mentioned it.

Hello,

Yes, we have a CLI for nearly everything, and both WP Workbench and the upcoming WP Workbench Manager will have full CLI support.

To create a new virtual server, use Virtualmin’s virtualmin create-domain command. To install an LE certificate, use virtualmin generate-letsencrypt-cert. To install a new WordPress app, use the virtualmin install-script sub-command. For WP Workbench, use virtualmin configure-script --app wordpress (currently it’s --script-type, but that will change to --app in the new release).

The upcoming Virtualmin and WP Workbench releases will let you manage multiple WordPress instances on one or more servers, update all instances, themes, and plugins at once, schedule backups, and handle many other automated tasks. The new API command will be virtualmin configure-all-scripts --app wordpress, and it comes with an extensive set of options.

When you run it, you’ll see detailed descriptions and plenty of examples.

You can also use the remote API as a domain user for both configure-script and configure-all-scripts, like this:

https://domain.tld:10000/virtual-server/remote.cgi?program=configure-script&app=wordpress&domain=domain.tld&opt=backup%20db

You’ll have to wait for this to go live in production, but the development versions are available at software.virtualmin.dev, which has the latest Virtualmin and WP Workbench (including Manager) if you want to test it out, especially since you seem quite tech-savvy.

1 Like

Awesome, thank you! This rocks! At least, so far :slight_smile:

I’m working through what you gave me, and struggling a bit on instaling Wordpress.

Do I need to create a database first? I’m hoping to use the existing user’s database, just specify the name to use, like if my user is “sampleuser”, I’d like to use e.g. “sampleuser_wp1” or somesuch.

Here’s what I have so far:

virtualmin install-script --domain example.com --type wordpress --version “latest” --path /public_html/ --db “mysql exampledb” --user username --pass password

It’s saying database exampledb doesn’t exist, but I confirmed it does in the database settings for the domain - there’s already three scripts using it, in fact… so maybe I’m missing something here…


Also for anyone looking to do this, here’s anonymized versions of the commands I used that might be something like the bare minimum that might help you along:

virtualmin create-domain --domain domain --pass “password” --parent example.com --email me@example.com --plan “Default Plan” --default-features

(In the above case, I wanted an existing site to be a parent, also meaning I didn’t specify a username…)

virtualmin generate-letsencrypt-cert --domain domain --default-hosts --email-always --web --dns

Make sure you know the right database name:

virtualmind list-databases --domain example.com

Then you can install WordPress:

virtualmin install-script --domain example.com --type wordpress --version “latest” --path / --user username --pass password

And that means this can be put together into a script!!!

No, you don’t. Installation script will handle it all for you.

I recommend against it. It’s better to have a separate database for each application, as this is a much better design.

It’s saying database exampledb doesn’t exist , but I confirmed it does

Is this database associated with the virtual server? You can check it by running virtualmin list-databases --domain example.com command. If not, you can import it by using virtualmin import-database.

1 Like

That did the trick.

And somehow I forgot that child sites still get their own db.

You rock so very much!

And while I hesitate to install the dev version of virtualmin… I will absolutely be playing with this when it hits release!

I write simple bash scripts, but I’ve had AI help me be lazy and write a script that prompts for information like domain name, username - but also sets defaults like my contact email and things like that - then allows me to choose what to do from a text menu (i.e. numbered list of options) - like install wordpress, the Divi theme I have stred in a location accessible to all users…

I’ll do a writeup of this proess at some point soon and post a link to it in case it helps others. :slight_smile:

Thank you for pointing me down the right path on this stuff!

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.