Install WordPress with wp-cli

01 May 2014

Here in StuntCoders, we’re using Vagrant for our development, and we’re writing bash scripts to automatically install platforms we need for our development (such as vagento).

Today we needed to automate WP installation and we figured the best way to do it is by using wp-cli. However, most of the wp-cli tutorials we’ve seen online have focused on showing how to use it with already installed WordPress. So, we’ve decided to put together one short script. We have included comments that should explain every step.

Install WordPress with wp-cli:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Set database for WordPress if it doesn't exist, add user, and grant privileges
mysql -u root -e "CREATE DATABASE IF NOT EXISTS wpdb"
mysql -u root -e "GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'password'"
mysql -u root -e "FLUSH PRIVILEGES"
 
# Get wp-cli and move it to bin
curl -L https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar
chmod +x wp-cli.phar & sudo mv wp-cli.phar /usr/bin/wp
 
# Create project folder and enter it
mkdir projectfolder & cd projectfolder
 
# Download WordPress
wp core download
 
# Set wp-config.php to match previously defined parameters for database
wp core config --dbname=wpdb --dbuser=wpuser --dbpass=password --extra-php <

It is simple as it looks. Now, go and have fun! :)

  • Was this helpful?
  • Yes   No
  • Back