Automate dir and DB stack creation with WP-CLI

WP-CLI has a bunch of helpful commands, including some to perform basic database operations.

However, it’s not its job to create new users in MySQL and grant them permissions on a newly created database. So that part of your script can’t really be replaced with WP-CLI.

You’re still in luck though. The wp core command will help you download, install, update and manage a WordPress install. Plus wp config helps you manage the wp-config.php file.

Instead of curl -L http://wordpress.org/latest.tar.gz | tar -zx -C ${domain}/ you can simply use wp core download to install the latest version of WordPress.

To add the database credentials to the config file, you can use wp config create --dname="${domain}" --dbuser="${domain}" --dbpass=${dbuserp}.

But we’re not done yet! Why not fully install WordPress while we’re at it? This can be done using wp core install:

wp core install --url=example.com --title=Example --admin_user=supervisor --admin_password=strongpassword [email protected]