Original post on my blog, happy to include feedback!
Cover: U.S. National Archives, via New Old Stock
--
These examples assume a working local WP-CLI helper –
for installing and file structure advice, see 4) installing WP-CLI.
- Setup vanilla Wordpress from scratch
- Migrate an existing instance
- Update an instance
- See also
- Further reading
1) Setup vanilla Wordpress from scratch
Assumes an existing local database and host.
# root dir is project dir
mkdir -p wordpress
cd wordpress
# download to current folder, see
# https://developer.wordpress.org/cli/commands/core/download/
wp core download --locale=en_GB
# TODO: using the password on the shell is not ideal, see
# https://developer.wordpress.org/cli/commands/config/create/#examples
wp config create --dbname=[name] --dbuser=[user] --dbpass=[pass]
# this will return a user password
wp core install --url=website.local --title="Website title" --admin_user="janitor" --admin_email="foo@bar.local"
# create local wp-cli config for htaccess generation, see
# https://developer.wordpress.org/cli/commands/rewrite/structure/
printf "apache_modules:\n\
- mod_rewrite\n" >> ../wp-cli.local.yml
# create htaccess
wp rewrite structure '/%year%/%monthnum%/%postname%/' --hard
TODO: add SQLite example
2) Migrate an existing instance
wp db reset --yes
gunzip [file.sql.gz] --stdout | wp db import -
# reset pw of user `admin` to `test`
wp eval "wp_set_password( 'test', get_user_by( 'login', 'admin' )->ID );"
# set local url
# needs http[s]:// protocol and quotes
wp option update siteurl 'http://domain.local'
wp option update home 'http://domain.local'
# flush redirects
wp rewrite flush
3) Update an instance
# update core
wp core update
# update all themes
wp theme update --all
# update all plugins
wp plugin update --all
# update language
wp language core update
wp language plugin --all update
wp language theme --all update
# update db scheme
# otherwise, an admin user will be prompted
wp core update-db
Note: paradoxically, a working wp-config.php
is mandatory for WP-CLI to work. You can use the helper command wp config create
if you don't want to clone wp-config-sample.php
manually.
Specify version and locale
wp core update --version=5.4 --locale=en_GB
Check locale availability via WP translation platform
4) See also
Globally installing WP-CLI vs keeping a local version
You can
or
- keep a local install in you're projects root folder e.g. at
/bin/wp-cli.phar
which makes sure each script continues to work on a remote installation.
Downloading core programmatically without WP-CLI
# grab and unpack the latest locale-specific release
curl https://de.wordpress.org/latest-en_GB.tar.gz -o latest-en_GB.tar.gz
tar -xvzf latest-en_GB.tar.gz
cd wordpress
5) Further reading
- alternative to downloading core: the Wordpress Skeleton
- applying
--allow-root
: php - Setting WordPress siteurl using wp-cli with WAMP virtual host - Stack Overflow - 13 Useful WordPress SQL Queries You Wish You Knew Earlier
Top comments (0)