Dev Notes

Various Cheat Sheets and Resources by David Egan/Carawebs.

WordPress CLI

Tools, WP-CLI, WordPress
David Egan

The WordPress CLI tool allows you to deploy WordPress and add themes & plugins from the command line.


Change to user that will own the WP install:

root@server:~# su username

Give proper ownership to a suitable directory and move into it:

sudo chown username -R var/www/
cd /var/www/

Install WP-cli:

sudo curl -L > wp-cli.phar

Make executable, move to make available across system:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/bin/wp

Get info about wp-cli to check the installation worked:

wp --info

Install WordPress Using WP-CLI

Create a new directory called “testsite”:

mkdir testsite

Give proper ownership:

sudo chown -R user:www-data /var/www/testsite

Download WP core:

wp core download

Create a MySQL Database:

mysql -u root -pROOTPASSWORD -e "create database db_name; GRANT ALL PRIVILEGES ON db_name.* TO new_user@localhost IDENTIFIED BY '12345'"

Configure WordPress to use it:

wp core config --dbname=db_name --dbuser=new_user --dbpass=1234567 --dbhost=localhost

Install WordPress:

wp core install --url=http://localhost/testsite --title="Basic Test Site" --admin_user=USERNAME --admin_password=STRONGPASSWORD --admin_email=USER@WEBSITE.COM

Using WP-CLI Deploy Plugin

Install WP-cli Deploy plugin in relevant WP directory:

git clone

Create a wp-cli.yml file in the root of you WordPress directory and add this line to the file:

require: "relative/path/to/deploy.php"

For example:

require: "wp-cli-deploy/deploy.php"

Enter wp help deploy to check it works.

To use WP-cli deploy, you need to define constants in wp-config.php.

For example, set up deploy for the “dev” environment:

    define( 'DEV_URL', '' );
    define( 'DEV_WP_PATH', '/var/www/' );
    define( 'DEV_HOST', '12.34.567.890' );
    define( 'DEV_USER', 'remote-server-username' );
    define( 'DEV_PORT', '22' );
    define( 'DEV_PATH', '/var/www/' ); # Path to remote site
    define( 'DEV_UPLOADS_PATH', '/var/www/' );
    define( 'DEV_THEMES_PATH', '/var/www/' );
    define( 'DEV_PLUGINS_PATH', '/var/www/' );
    define( 'DEV_DB_HOST', 'localhost' );
    define( 'DEV_DB_NAME', 'databaseName' );
    define( 'DEV_DB_USER', 'databaseUser' );
    define( 'DEV_DB_PASSWORD', '1234567goodpassword' );

Deploy Database and uploads to dev environment:

wp deploy push dev --what=db && wp deploy push dev --what=uploads

Necessary Local Ownership Local

Set permissions: allow rwx for user & group, r for others

Remote Ownership: Example drwxr-xr-x 5 USERNAME www-data 4096 May 5 17:20 testsite

comments powered by Disqus