The WordPress Command Line Interface (CLI) is a tool that allows you to install and configure WordPress via a console. This is useful when installing WordPress via a secure shell connection. The cheat sheet provides commands for downloading and installing WordPress, creating a config file, creating a database, installing and managing themes and plugins, and managing posts. To use the CLI, you need to install it by downloading the repository via Curl, making the file executable, and moving it to your PATH. You can update the CLI using the command "wp cli update".
Type | Task | Command |
---|---|---|
Core | Download WordPress. | wp core download |
Core | Generate wp-config.php file. | wp core config -dbname=<database> -dbuser=<user> -dbpass=<password> -dbprefix=<prefix> |
Core | Install WordPress. | wp core install -url=”your domain name” -title=”Your blog title” -admin-user=”admin” -admin_password=”your_password” -admin_email=”your_email” |
Core | Update WordPress | wp core update |
Core | Update WordPress Database | wp core update-db |
Database | Login to WordPress | wp db cli |
Database | List WordPress users | wp db query “SELECT user_login, ID FROM wp_users;” |
Database | Optimize the database | wp db optimize |
Plugin | Search for a Plugin | wp plugin search <plugin> |
Plugin | Install a Plugin | wp plugin install <plugin-name> |
Plugin | List all installed Plugins | wp plugin list |
Plugin | Update (all) plugins | wp plugin update <plugin-name> -all |
Theme | List all installed Themes | wp theme list |
Theme | Search for a Theme | wp theme search <keyword> |
Theme | Install a Theme | wp theme install <theme-name> |
Theme | Activate a Theme | wp theme activate <theme-name> |
Theme | Update (all) themes | wp theme update <theme-name> —all |
Post | List all posts | wp post list |
Post | Edit a post | wp post edit <post-id> |
Post | Update a post | wp post update <post-id> |
Post | Create a post | wp post create —post_status=publish —post_title=”post title” —edit |
Post | Change post author | wp post update <post-id> —post_author=<user-id> |
First, download the repository via Curl:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Check if it works using the following command:
php wp-cli.phar --info
To be able to type just wp
, instead of php wp-cli.phar
, you need to make the file executable and move it to somewhere in your PATH. For example:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Now try running wp --info
. If WP-CLI is installed successfully, you’ll see output like this:
OS: Linux 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64
Shell: /usr/bin/zsh
PHP binary: /usr/bin/php
PHP version: 7.1.12-1+ubuntu16.04.1+deb.sury.org+1
php.ini used: /etc/php/7.1/cli/php.ini
WP-CLI root dir: /home/wp-cli/.wp-cli
WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/
WP-CLI global config: /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 1.5.0
Update the CLI using the following command:
wp cli update
Go to the directory where you would like to install WordPress. Once in the directory, use the following command:
wp core download
Run the following command using the correct information for your website:
wp config create --dbname={database name} --dbuser={database username} --dbpass={database password}
If you didn’t create a database for your website, you can use the CLI to create it for you.
wp db create
Run the following command to install WordPress.
wp core install --url={your domain} --title={your blog title} --admin_user={username} --admin_password={password} --admin_email={your email}
Every theme has a unique identifier. The identifier for the theme is its slug name, which can be found on the WordPress page for that theme. Find that theme on WordPress.org and use the name in the URL.
Once you have the theme name, install it using:
wp theme install {theme name}
You can activate it using:
wp theme activate (theme name)
To remove the theme, run:
wp theme delete {theme name}
You can update a single theme by using its identifier:
wp theme update (theme name}
You can update all of your themes at once using --all.
wp theme update --all
Like themes, every plugin has a unique identifier. The identifier for the theme is its slug name, which can be found on the WordPress page for that plugin. Find that plugin on WordPress.org and use the name in the URL.
Once you have the theme name, install it using:
wp plugin install {plugin name}
You can activate it using:
wp plugin activate (plugin name)
To remove the theme, run:
wp plugin delete {plugin name}
You can update a single plugin by using its identifier:
wp plugin update (plugin name}
You can update all of your plugins at once using --all.
wp plugin update --all