# WP-CLI - Automation of WordPress developer routine

- Canonical: https://asgru.com/wp-cli-automation-of-wordpress-developer-routine/
- Language: en
- Author: asgru
- Published: 2024-05-26T07:54:52+02:00
- Updated: 2024-05-26T07:54:52+02:00

## Introduction

Automation of routine tasks is an essential aspect of any developer’s work. In the world of WordPress, this is especially relevant, as the platform offers numerous tools for automation through the command line. One such tool is WP-CLI (WordPress Command Line Interface), which allows for quick and efficient execution of many site development and administration operations.

## Basic WP-CLI Commands for Installing WordPress

WP-CLI offers a wide range of commands that simplify the process of installing and configuring WordPress. Let’s look at the basic steps for installing WordPress using WP-CLI.

- Installing WP-CLI:
First, you need to install WP-CLI. This is typically done by running the following command in the terminal:

 curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
 php wp-cli.phar --info
 chmod +x wp-cli.phar
 sudo mv wp-cli.phar /usr/local/bin/wp

- Downloading WordPress:
To download the latest version of WordPress, use the command:

 wp core download

- Creating the Configuration File:
The following command creates the wp-config.php file with the specified database parameters:

 wp config create --dbname=your_db_name --dbuser=your_db_user --dbpass=your_db_password --dbhost=localhost --dbprefix=wp_

- Installing WordPress:
Command for installing WordPress with the specified site parameters:

 wp core install --url=your_site_url --title="Your Site Title" --admin_user=your_username --admin_password=your_password --admin_email=your_email@example.com

## Installing the Necessary Plugins

Plugins are an important part of the WordPress ecosystem, and WP-CLI greatly simplifies their installation and management. For example, to install several popular plugins, you can use the following commands:

- Installing and Activating Plugins:

 wp plugin install akismet --activate
 wp plugin install jetpack --activate
 wp plugin install yoast-seo --activate

- Bulk Installation of Plugins from a List:
Create a file named plugins.txt with a list of plugins, one per line. For example:

 akismet
 jetpack
 yoast-seo
 contact-form-7

Then use the following command for bulk installation and activation:

 wp plugin install $(cat plugins.txt) --activate

## Installing a Theme Stub

Sometimes developers need to create or install a “stub” theme for initial setup or testing. WP-CLI allows for this to be done quickly as well.

- Creating a New Theme:
WP-CLI can help create a new theme with a basic structure:

 wp scaffold theme my-theme --activate

- Installing a Theme Stub:
There are also ready-made theme stubs that can be installed. For example, to install the twentytwentyone theme:

 wp theme install twentytwentyone --activate

## Conclusion

Using WP-CLI greatly simplifies and accelerates the process of installing, configuring, and administering WordPress. It allows automating most routine tasks, freeing up time for more complex and creative aspects of development. By mastering the basic WP-CLI commands, developers can increase their productivity and reduce the number of errors that occur when performing repetitive operations manually.
