Table of Contents
Table of Contents
WP-CLI is one of the command line tools specifically made to manage your WordPress websites through the command line. You can manage WordPress without even needing to login to your WordPress admin and navigate through the pages. WP-CLI will be particularly useful if you are a WordPress developer, System Administrator or run a business built around WordPress.
This command line tool will greatly help you do more in less time , for example taking backups, updating WordPress and plugins, publishing content and querying databases can be accomplished relatively quickly.
Here are the requirements of WP-CLI needed
Follow these steps to install WP-CLI, a command-line tool for managing WordPress installations
Step: 1 Download the WP-CLI Tool
Download the WP-CLI apparatus from Github with the accompanying order
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step: 2 Verify the Download
After the download verify that the WP-CLI Phar file has been downloaded successfully by checking its information
php wp-cli.phar –info
Step: 3 Make WP-CLI Executable
Presently you need to set wp-cli.phar to be an executable document. Just enter the following command
chmod +x wp-cli.phar
Step: 4 Move WP-CLI to a System-Wide Location
Finally, move the executable file to a directory that’s in your system’s PATH, so you can run wp from any location
sudo mv wp-cli.phar /usr/local/bin/wp
Now that WP-CLI is installed, you can start managing your WordPress site from the command line. This powerful tool allows you to perform various tasks such as updating plugins, managing themes, and much more, all through the terminal.
Step 1: Download WordPress
We need to download WordPress in order to install it. Navigate to the directory you’d like to download the WordPress CMS to and run the following command
wp core download
Step 2: Create a New Database User
To create a new MySQL database user, log in to the MySQL command line and execute the following commands
Using below command log in to the MySQL
mysql
After login to mysql use these commands to create a database, create a database user, and grant privileges to the user on the database.
CREATE USER ‘databaseuser’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON *.* TO ‘databaseuser’@’localhost’;
FLUSH PRIVILEGES;
Step 3: Create the “wp-config.php” File
This command will download the latest version of WordPress after Download is completed. your can create wp-config.php file using following commands
wp core config –dbname=databasename –dbuser=databaseuser –dbpass=password –dbhost=localhost –dbprefix=wp_ –allow-root
This command displays all of your login credentials in the wp-config.php file. Now the wp-config.php file is created.
Step 4: Create the Database
create a fresh database with the name specified in the wp-config.php file
wp db create
Step 5: Install WordPress
Execute the core install command to complete the WordPress installation
wp core install –url=example.com –title=”WordPress Website Title” –admin_user=admin_user –admin_password=admin_password –[email protected]
First, navigate to your WordPress directory, then execute the command to list installed themes:
wp theme list
The output looks like this:
Activate a Theme
To activate a theme, use the following command
wp theme activate twentynineteen
Have a quick look into the wp-config.php
This command shows the output of wp-config.php
wp config get
Get the Path of wp-config.php
Use the following command to get the path
wp config path
Example output
Using WP-CLI to Run Core Updates
Run the following command to update WordPress core
wp core update
To check the current version of WordPress, use
wp core version
Managing Plugins with WP-CLI
To list all installed plugins, use
wp plugin list –allow-root
To deactivate a plugin, use
wp plugin deactivate <plugin_name>
wp plugin deactivate akismet
To delete a plugin, use:
wp plugin delete hello
To update all plugins use this command,
wp plugin update –all
To check the status of plugins
wp plugin status
Using WP-CLI to Search and Replace
To search and replace text within your WordPress database, use:
wp search-replace –dry-run ‘example.com’ ‘sample.example1.com’
Installing a Plugin Through WP-CLI
To install a plugin, use:
wp plugin install woocommerce
Resetting User Passwords
To reset a user password, use:
wp user update root_root –user_pass=sample@123
To reset a user password and update the display name, use:
wp user update root_root –display_name=admin –user_pass=sample1@123
By following the steps outlined above, you can efficiently use WP-CLI to install and manage your WordPress site. This includes downloading and configuring WordPress, creating databases and users, and handling themes and plugins. WP-CLI provides a powerful command-line interface for WordPress management, enabling you to automate tasks and streamline your workflow. Whether you are performing updates, managing users, or configuring settings, WP-CLI offers a robust and efficient way to interact with your WordPress site. Keep this guide handy as a reference for your future WordPress projects and continue exploring more advanced WP-CLI commands to further enhance your site’s management.