Skip to content

WP Client

Documentation

This is a step-by-step tutorial. Reading the Panda installation notes and our WP Core docs is assumed.

Click here to see the full documentation…

Introduction

Summary

Panda can be controlled in various ways, one of it being the command-line client or CLI.

WP Client allows easy and automated maintenance of both database and server.

In detail the backend consists of the following key components:

  • Web server
  • PHP server for development
  • Apache or Nginx server for production
  • GUI dashboard or admin interface based on WP Core
  • CLI client
  • REST API
  • SQL database

Hint

It is recommended to use the CLI or the API instead of the GUI for scripts and regular tasks.

Overview

Summary

This tutorial covers the most important CLI commands.

See wp help or wp.org for a full list of available commands.

In this tutorial we will learn how to…

  • Get system information like the path of the wp binary or the php.ini file.
  • Manage environment variables and .env files, including secrets.
  • Install, update, and manage the core installation.
  • Read and set site options, including plugin and theme settings.
  • Perform database operations and connect to the MySQL console.
  • …and more.

First steps

Summary

Let us start with some basics: Command name, system information, and client updates.

Command name

Note

Before starting we need to know the exact path to the wp binary.
This document will use wp without path for better readability.

The command name may vary depending on our installation.

  • When using Composer

    ./vendor/wp-cli/wp-cli/bin/wp (or the ./vendor/bin/wp symlink)

  • When using Docker

    docker exec wp-cli wp (or docker-compose exec wp-cli wp)

  • For global or system-wide installations

    wp

System information

Summary

Whenever information about the current system is needed, the wp cli info or wp --info command is our friend.

The client will retrieve the following:

  • OS information
  • Shell information
  • PHP binary used
  • PHP binary version
  • php.ini configuration file used, which is typically different than web
  • WP CLI root dir, i.e. where the client is installed (if non-Phar install)
  • WP CLI global config, i.e. where the global config YAML file is located
  • WP CLI project config, i.e. where the project config YAML file is located
  • WP CLI version, i.e. the currently installed release

So in cases where changes to the php.ini are needed, the CLI shows us the path.

Command

Display details about the current installation.

wp --info

Example

The output might look as follows.

Name Value
OS Linux 5.4.0-44-generic
Shell /bin/zsh
PHP binary /usr/local/bin/php
PHP version 7.3.11
php.ini used /etc/php/7.3/cli/php.ini
WP-CLI root dir phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir phar://wp-cli.phar/vendor
WP_CLI phar path /var/www/html
WP-CLI packages dir /home/redtux/.wp-cli/packages/
WP-CLI global config /var/www/wp-cli.yml
WP-CLI project config /var/www/wp-cli.yml
WP-CLI version 2.4.0

See wp help cli or wp.org for more options.

Client updates

Command

Check for updates.

wp cli check-update

Success: WP-CLI is at the latest version.

Command

Update the client to the latest release.

wp cli update --nightly --yes

Warning

Phar files have self-updating powers. As shown below, this will not work when using Composer or Docker.

Error: You can only self-update Phar files.

Environment

Summary

wp dotenv manages all environment variables defined in an .env file.

./.env is set as default. This can be changed by using the --file parameter.

Command

List the content of the .env.example file.

wp dotenv list --file=.env.example

Example

The output might look as follows.

Variable Value
DB_HOST db
DB_PREFIX wp_
DB_ROOT_PASSWORD database_root_password
DB_NAME database_name
DB_USER database_user
DB_PASSWORD database_password
DOCROOT /var/www/htdocs
WP_ENV development
WP_HOME https://localhost
WP_SITEURL https://localhost/wp
WP_DEBUG_LOG /var/log/debug.log
WP_TITLE Panda-CMS
WP_ADMIN_USER admin_user
WP_ADMIN_PASSWORD admin_password
WP_ADMIN_EMAIL mail@example.com
SFTP_HOST sftp.example.com
SFTP_USER remote_user
SFTP_PASSWORD remote_password
AUTH_KEY generateme
SECURE_AUTH_KEY generateme
LOGGED_IN_KEY generateme
NONCE_KEY generateme
AUTH_SALT generateme
SECURE_AUTH_SALT generateme
LOGGED_IN_SALT generateme
NONCE_SALT generateme

See wp help dotenv or wp-dotenv for more options, and phpdotenv for further information.

Core installation

Command

Run Panda Core installation process and populate the database.

wp core install \
        --path=$DOCROOT/wp \
        --url=$WP_HOME \
        --title=Panda-CMS \
        --admin_user=$WP_ADMIN_USER \
        --admin_password=$WP_ADMIN_PASSWORD \
        --admin_email=$WP_ADMIN_EMAIL

See wp help core or wp.org for more options.

Options and settings

Summary

Configure Panda settings like site description, title, theme, URL, or mail server.

Site title

Command

Get the site name or title.

wp option get blogname

Output

Panda-CMS

Command

Change the site name or title.

wp option update blogname "Panda"

Output

Success: Updated 'blogname' option.

Site description

Command

Update the site description.

wp option update blogdescription "Next Generation E-Commerce Platform"

Output

Success: Updated 'blogdescription' option.

Time zone

Command

Set the time zone.

wp option update timezone_string "Europe/Vienna"

Output

Success: Updated 'timezone_string' option.

Time format

Command

Set the time format.

wp option update time_format "H:i"

Output

Success: Updated 'time_format' option.

Date format

Command

Set the date format.

wp option update date_format "j. F Y"

Output

Success: Updated 'date_format' option.

URL format

Hint

In case you do not know what permanent links are and how to use them, see Using Permalinks.

Command

Set the permalink structure to use the post title in the URL.

wp rewrite structure '/%postname%/'

Output

Success: Rewrite structure set.
Success: Rewrite rules flushed.

Command

Display .htaccess permalink rewrite rules

wp rewrite list --format=csv

See wp help rewrite or wp.org for more options.

Options help

See wp help option or wp.org for further assistance.

Database management

List tables

Command

List database tables.

wp db tables

Display size

Command

Display the size of all tables in human readable format.

wp db size --tables --human-readable

Example

The output might look as follows.

Name Size
wp_commentmeta 50 KB
wp_comments 99 KB
wp_links 33 KB
wp_options 2 MB
wp_postmeta 50 KB
wp_posts 82 KB
wp_term_relationships 33 KB
wp_term_taxonomy 50 KB
wp_termmeta 50 KB
wp_terms 50 KB
wp_usermeta 50 KB
wp_users 66 KB

Check integrity

Command

Check database integrity.

wp db check

Output

Success: Database checked.

DB optimization

Command

Optimize the database running mysqlcheck -optimize=true.

wp db optimize

Output

Success: Database optimized.

DB export

Command

Export the database to an SQL file running mysqldump.

wp db export --porcelain

Hint

The PROCESS privilege for the DB_USER is needed for this operation. Use:
GRANT PROCESS ON *.* TO 'db_user'@'%';

DB import

Command

Import a database dump from an SQL file.

wp db import <file>

MySQL client

Command

Open the SQL console using the mysql client.

wp db cli

Database help

See wp help db or wp.org for further assistance.

Theme menus

Command

List available menu locations for the current theme.

wp menu location list

Example

The output might look as follows.

Location Description
primary Desktop Horizontal Menu
expanded Desktop Expanded Menu
mobile Mobile Menu
footer Footer Menu
social Social Menu

Command

Create a new menu.

wp menu create "Panda Menu"

Output

Success: Created menu 2.

Command

Assign the new menu to the primary menu location.

wp menu location assign panda-menu primary

Output

Success: Assigned location primary to menu panda-menu.

Display menus

Command

Gets a list of menus.

wp menu list

Example

The output might look as follows.

term_id Name slug locations count
2 Panda Menu panda-menu primary 0

Custom menus

Command

Add custom menu items to the navigation bar.

wp menu item add-custom panda-menu "🐼 Code" https://github.com/pandainfo/panda --porcelain
wp menu item add-custom panda-menu "📘 Docs" https://pandainfo.github.io/panda --porcelain

List menu items

Command

Get a list of items associated with a menu.

wp menu item list panda-menu

Example

The output might look as follows.

DB ID Type Title Link Position
10 custom 🐼 Code pandainfo/panda 1
11 custom 📘 Docs https://pandainfo.github.io/panda 2

See wp help menu or wp.org for more options.


Last update: January 28, 2021