1. Home
  2. CMS/Applications
  3. How to Manage WordPress in CLI with wp-cli

How to Manage WordPress in CLI with wp-cli

Introduction

You can install and configure a new WordPress site with N0C (how). However, sometimes it can be advantageous to install a WordPress site in command line. To do this, you need to use thewp-cli tool.

Warning : The article does not explain how to design a website in WordPress, which you can find in the WordPress Support on the Web: https://wordpress.org/support/.

Note : The N0C Glossary contains explanations on multiple topics and can be consulted to clarify certain terms.

Preparation

Enter the following address in your web browser: https://mg.n0c.com/en/.

Note : wp-cli is installed natively with the automatic installer of N0C and it is accessible in SSH via the wp command.

Installing a WordPress Website

Preparation

To install a WordPress site on the hosting with the help ofwp-cli, you must first :

  • Create a database, a user with a password and authorize the database user with the N0C panel (how).
  • Logging in with a password (how).

Installation of the Website

The process is explained with the help of an example, where we will install a WordPress website in thepublic_htmldirectory of the hosting. In this example, the dummy address of the site that points to this directory is https://mydomain.ca :

# Downloading WordPress
wp core download
# Production of the configuration file
cd ~/public_html
wp core config --dbname="database_wp" --dbuser="user_wp" --dbprefix="mywp_" --dbpass="pass_database"
# Launching the installation
wp core install --url="https://mydomain.ca" --title="Site WordPress" --admin_user="adminname" --admin_password="mypassword" --admin_email="admin@test123.ca"
# Change of link structure to keep the article name only
wp rewrite structure '/%nameofpost%'

Where :

  • database_wp: database name.
  • user_wp: database username.
  • mywp_: the prefix.
  • pass_database: password to access to the database.
  • Site WordPress: name of the site.
  • adminname: name of the administrator.
  • mypassword: password of the administrator.
  • admin@test123.ca: e-mail of the administrator.
  • nameofpost: post name.

By default, the language of WordPress is English. However, should you need to define another language, you would have to enter the following command (in this exemple, French is chosen):

# Changing the WordPress language for French
wp core language list
wp core language install --activate fr_FR

Note : It is best to use alphanumeric characters for passwords (avoid special characters).

Installation of a Theme

A new custom theme available in the WordPress theme repository can be installed. The command also allows you to specify a link to the zip archive of a theme or an HTTPS address to a themes zip file.

# Display the list of themes that can be found in the installation
wp theme list
# Installation of a new theme (generatepress)
# https://wordpress.org/themes/generatepress/
wp theme install generatepress
# Activation of the theme
wp theme activate generatepress

Note : After activation, if an error indicates that the parent theme is needed, just install it with the command “wp theme install” followed by the theme name.

Installation of a Plug-In

To install a plug-in, you just have to give the name of the plug-in and the command will automatically fetch it from the WordPress repositories. The command also allows you to indicate a path to a zip file of an extension or an HTTPS address to a zip file of plug-ins.

# Display of the list of detected plug-ins
wp plugin list
# Installation of the classic-editor plug-in
wp plugin install classic-editor
# Activation of the plug-in
wp plugin activate classic-editor

Note : The “–activate” command allows you to activate and install the plug-in at the same time.

Updates

The wp-cli tool allows you to manage updates for WordPress, themes and plug-ins. However, each module must be updated individually using theupdate command.

# Check to see if updates are available
wp core check-update
# WordPress core update
wp core update
# Database update
wp core update-db
# Check to see if extension updates are available
wp plugin update --all --dry-run
# Update all plug-ins
wp plugin update --all
# Check to see if themes updates are available
wp theme update --all --dry-run
# Update all themes
wp theme update --all

References About wp-cli Commands

The basic wp-cli commands are available via this link: https://developer.wordpress.org/cli/commands/.

Updated on February 8, 2024

Related Articles