Installing WordPress from the command line

Sometimes you just need a step-by-step guide to copy+paste

Set variables

user='www-data'
group='www-data'
dbuser='testuser'
dbname='testdb'
dbpass='123abc'
url='https://xn--1ca.se'
title='ThePingPongPlatform'
admin_name='admin'
admin_pass='123abc'
admin_email='j@asbra.nu'

Add database and user

# mysql -v -e"create database ${dbname};"
# mysql -v -e"grant all on ${dbname}.* to ${dbuser}@localhost identified by '${dbpass}'"

Verify

# mysql -e'show databases'
# mysql -e'select user,host from mysql.user'

WP-Cli

# curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
# chmod +x wp-cli.phar
# cp wp-cli.phar /usr/bin/wp

Core install

# sudo -u $user -s
# wp core download
# wp core config --dbhost=$dbhost --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass
# chmod 644 wp-config.php
# wp core install --url=$url --title="$title" --admin_name=$admin_name --admin_password=$admin_pass --admin_email=$admin_email