Besides resetting a WordPress password using the database, did you know that we can reset a WordPress password using WP-CLI?
What is WP-CLI?
WP-CLI is a Command Line Interface for managing WordPress where you can perform updates, change configurations, and make other changes to WordPress using the Command Line without having to use a browser.
Does that mean it is harder to use? Well, it might not be wrong to say it is harder because when using WP-CLI, you have to find out the command you want to use to make changes.
On the other hand, it becomes simpler to use, where you can use just one command to run a process. For example, to install a plugin via a browser, you need to open the admin dashboard, then open the plugins page, search for the plugin, and finally install it.
It is different when using WP-CLI, as you can install a plugin directly with just one command.
How to Reset a WordPress Password Using WP-CLI
Before resetting a WordPress password using WP-CLI, you obviously need to install WP-CLI first, because by default, WP-CLI is not installed on the server.
1. Install WP-CLI on Linux
The first step to installing WP-CLI is to download wp-cli.phar to your server, either using wget or curl. So make sure that wget or curl is already installed on your server.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharwget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharAfter you download wp-cli.phar, make sure that the file is working correctly.
php wp-cli.phar --infoIf successful, you will get information similar to this.
OS: Linux 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Fri Sep 16 14:08:19 EDT 2022 x86_64Shell: /usr/bin/zshPHP binary: /usr/bin/phpPHP version: 7.4.33php.ini used: /etc/php/7.1/cli/php.iniMySQL binary: /bin/mysqlMySQL version: mysql Ver 15.1 Distrib 10.6.13-MariaDBWP-CLI root dir: /home/wp-cli/.wp-cliWP-CLI packages dir: /home/wp-cli/.wp-cli/packages/WP-CLI global config: /home/wp-cli/.wp-cli/config.ymlWP-CLI project config:WP-CLI version: 1.5.0Okay, up to this point, WP-CLI has been successfully added, but to use WP-CLI, you must use the command php wp-cli.phar and it is certainly still long.
So that we can use it with just the command wp, we need to make the wp-cli.phar file an executable file and move it to a specific folder on your server. For example,
chmod +x wp-cli.pharsudo mv wp-cli.phar /usr/local/bin/wpNow you can use WP-CLI with the command wp. For example, to check the WP-CLI version, you can use the command wp --info, and the result will be something like this.
OS: Linux 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Fri Sep 16 14:08:19 EDT 2022 x86_64Shell: /usr/bin/zshPHP binary: /usr/bin/phpPHP version: 7.4.33php.ini used: /etc/php/7.1/cli/php.iniWP-CLI root dir: /home/wp-cli/.wp-cliWP-CLI packages dir: /home/wp-cli/.wp-cli/packages/WP-CLI global config: /home/wp-cli/.wp-cli/config.ymlWP-CLI project config:WP-CLI version: 1.5.02. Reset a WordPress Password Using WP-CLI
Because WP-CLI can now be executed, the next step is to open the WordPress installation folder where you want to change the password. For example, if our WordPress installation is in the folder /var/www/wpgan/, then open that folder.
cd /var/www/wordpress/After being in the WordPress installation folder, we need to find the list of WordPress users on our website using WP-CLI.
wp user listAfter that, you will get the current list of WordPress users. The output example is like this.
Based on the output above, if you want to change the password for the user admin, you can use the user ID of that user to change the password. For example, for the user admin using ID 1, the command used is like this.
wp user update 1 --user_pass=TulisPasswordBaruDisiniIf you want to change the password for the account user3, then the command used becomes like this.
wp user update 3 --user_pass=TulisPasswordBaruDisiniIf you are done, you can then log in to WordPress directly using the new password you created using WP-CLI.
Conclusion
The method of changing a password using WP-CLI is indeed easier than other methods, but this method is recommended if you are using a VPS, because not all hosting supports the SSH feature.
Besides that, if you use SSH on hosting, you might have difficulty moving the file wp-cli.phar, so you have no choice but to use the command php wp-cli.phar if you want to use WP-CLI on hosting.
COMMENTS
Loading...