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 , example taking backups, updating WordPress and plugins, publishing content and querying databases can be accomplished relatively quickly.
Requirements of WP-CLI
1 – PHP 5.3.2 or later.
2 – WordPress 3.4 or later.
3 – UNIX like environment like Linux.
Installing WP-CLI
Step#1
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
Then, affirm that it has been downloaded effectively:
php wp-cli.phar –info
Step#3
Presently you need to set wp-cli.phar to be an executable document. Just enter:
chmod +x wp-cli.phar
Step#4
To conclude the establishment, move everything into the last area:
sudo mv wp-cli.phar /usr/local/bin/wp
Since WP-CLI is introduced, you can begin working with your WordPress substance and records through the order line.
Installing WordPress with WP-CLI
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
How to Create a New User
root@root:/var/www/test# mysql
MariaDB [(none)]> CREATE USER ‘databaseuser’@’localhost’ IDENTIFIED BY ‘password’;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON * . * TO ‘databaseuser’@’localhost’;
MariaDB [(none)]> FLUSH PRIVILEGES
This command will download the latest version of WordPress after Download is completed. your can create wp-config.php file using following commands
root@root:/var/www/test# wp core config –dbname=databasename –dbuser=databaseuser –dbpass=password –dbhost=localhost –dbprefix=wp_ –allow-root
root@root:/var/www/test#
This command displays all of your login credentials in wp-config.php file. Now wp-config.php file is created
Create Database
This command will create a fresh database with the name used in wp-config file
wp db create
Install WordPress
Execute this core install command
wp core install –url=example.com –title=”WordPress Website Title” –admin_user=admin_user –admin_password=admin_password –admin_email=admin@example.com
Using WP-CLI to Install and Manage WordPress Themes
you must change path of wordpress directory then execute the command
root@root:/var/www/html# wp theme list
+—————–+———-+———–+———+
| name | status | update | version |
+—————–+———-+———–+———+
| twentynineteen | inactive | available | 1.8 |
| twentytwenty | inactive | none | 1.6 |
| twentytwentyone | active | available | 1.0 |
+—————–+———-+———–+———+
Activate Theme in wp-cli command using
root@root:/var/www/html# wp theme activate twentynineteen
Have a quick look into the wp-config.php
This command shows the output of wp-config.php
root@root:/var/www/html# wp config get
Get config path using below commands
root@root:/var/www/html# wp config path
/var/www/html/wp-config.php
Using WP-CLI to run core updates
root@root:/var/www/html# wp core update
Adding the version flag to your command and rolling back to the point where there wasn’t a conflict
root@root:/var/www/html# wp core version
wp command using get list of plugins
root@root# wp plugin list –allow-root
+———+———-+———–+———+
| name | status | update | version |
+———+———-+———–+———+
| akismet | inactive | available | 4.1.7 |
| hello | inactive | none | 1.7.2 |
+———+———-+———–+———+
Update, disable, and delete akismet plugins
Deactivate plugin
root@root:/var/www/html# wp plugin deactivate akismet
Activate plugins using wp commands
root@root:/var/www/html# wp plugin activate akismet
Delete plugin using Wp-command
root@root:/var/www/html# wp plugin delete hello
Update all plugins
root@root:/var/www/html# wp plugin update – all
Check the status of the plugins currently on your site
root@root:/var/www/html# wp plugin status
Using WP-CLI to Search and Replace
root@root:/var/www/html# wp search-replace –dry-run ‘example.com’ ‘sample.example1.com’
Installing a Plugin Through WP-CLI
root@root:/var/www/html# wp plugin install woocommerce
Reset user passwords using wp command
root_root >> username or email address
sample@123 >> password
root@root:/var/www/html# wp user update root_root –user_pass=sample@123
Reset user passwords using wp command with Display name
root@root:/var/www/html# wp user update root_root –display_name=admin –user_pass=sample1@123