What is WP-CLI?
WP-CLI is a command-line tool that allows users to manage their WordPress sites directly from the command line. Most of the developers want speedy, efficient, and quick tools to manage their websites.
Rather than using a web browser, you can update plugins, set up multisite installations, upgrades, backups can be created, publish new articles, and most of the common admin tasks can be carried out using a set of commands. All of this and more is provided by the WP-CLI while allowing you to administer your WordPress site.
Significance and Merits of using WP-CLI:
Due to the extraordinary features of Wp-CLI, it is gaining popularity due to multiple reasons in the WordPress developer’s community since it is easy to operate for the user of every level, starting from the beginner to the advanced level user. WordPress dashboard can now be managed by using WP-CLI.
You can manage multiple tasks using a command-line interface such as taking backups of your core files and database, publishing a new post, updating core files, updating themes, plugin installations, troubleshooting issues, managing users on a multi-site installation, and other core operations, etc.
On the other hand, using the command line requires a better understanding of what’s going on on your server and how to execute certain operations using special commands.
Some of the core functions and features of using WP-CLI is given below:
- Updating the themes
- Updating the plugins
- Fresh WordPress installation
- Updating the core WordPress framework
- Uploading media files in a bulk
- Creating database backups and recovering an existing database
- Creating a user’s account
- Changing user’s account
- Easy search and replace functions within the database.
- Download and add test content
To use the WP-CLI, you’ll need to install it on your WordPress site, but on Devrims Platform, you don’t have to do it manually because we have it pre-installed in all our servers and it can be accessed instantly.
So let’s start managing WordPress using WP-CLI.
First, you must connect your server via SSH or SFTP using Master User or Application User.
Note: You can see the instructions on how to connect your application via SSH and SFTP from our knowledge base article.
Managing WordPress Site Using Some Core WP-CLI Commands
Here are some of the useful practices you can adopt using WP-CLI on your site to get started with WP-CLI.
Once you connect SSH using the credentials, Go to the application webroot folder, i.e., public_html.
- Reading and Writing WordPress Configuration
Command: wp config list
The config command can read and write the WordPress configuration wp-config.php file.
- Changing WordPress User Passwords
Command: wp user update USERNAME – user_pass="new_password"
You can change the password of your site’s admin account with this command.
- Installing Core, Themes, and Plugins
Command (to install a theme): wp theme install twentytwenty – activate
Command (to update all plugins at the same time): wp plugin update – all
- Backup your Site’s Database
To take your site’s MySQL database backup in the cPanel interface is simple. If you prefer to backup via the terminal, use the following command:
Command: mysqldump -u database_username -p database_name > backup.sql
- To Restore the Database
Command: mysql -u database_username -p database_name > backup.sql
- Database Search and Replace
When changing the URL of your site or any particular string with another, the database search and replace command enable you to make the changes recursively into your site’s folder and will prove to be a very useful way of making changes to the site as per the new URL as well as into the database.
We strongly suggest running a dry-run command to check all the tables where the search & replace function will run.
wp search-replace 'http://olddomain.com' 'http://newdomain.com' --dry-run
After the successful dry-run, then run the below command to do the search & replace
wp search-replace 'http://olddomain.com' 'http://newdomain.com'
- Change WordPress URL
There could be a number of reasons why the URL of a website needs to be changed. Updating from www to non-www, transferring files, or migrating from HTTP to HTTPS are all possibilities. Whatever these cases may be, you can easily use the command:
wp option update home 'http://example.com'
wp option update siteurl 'http://example.com'
- Manage WP-Cron Events
You can manage the WP-Cron events and or WordPress Cron job using WP-CLI. For example, the below command will give you the current cron event list.
Command: wp cron event list
We are sure that following these steps you must have been able to perform your intended actions and achieve desired results.