Installing and Working With WordPress CLI
Posted By : Harsh Soni | 28-Feb-2018
In this tutorial, we are going to work with Wordpress command line interface (WP-CLI). It is specifically developed to manage WordPress websites using CLI. As it makes the WordPress work easier, it also allows working faster with WordPress. We can manage WordPress and its setting without navigating and clicking on several pages.
Using WordPress CLI we can complete the administrative tasks like updating themes, plugins installations, publishing post and many more. Before installing WP-CLI, You should make sure your hosting account has SSH access to you.
- PHP(5.3.2 or later)
- WordPress (3.4 or later)
- UNIX like environment like Ubuntu, Linux.
Open the terminal and paste the below code
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
It will download the WP-CLI files to your root directory. Now, we will make it executable by using this command.
chmod +x wp-cli.phar
type this to check if it works
php wp-cli.phar --info
to use "wp" at command start instead of "php wp-cli.phar" move the wp-cli.phar file to a wp directory
sudo mv wp-cli.phar /usr/local/bin/wp
Now we can execute WP-CLI commands by using 'wp'. You can also try "wp --info" command.
Installing WordPress setup on the server using WP-CLI.
We can install the WordPress using a single command "wp core install". Only we have to pass few parameters such as site name, admin name, URL etc.
wp core install --url="DomainURL" --title="Website Title" --admin_user="adminUsername" --admin_password="adminPassword" --admin_email="adminEmail"
Installing themes and plugins using WP-CLI
If you have spent lots of time clicking and installing plugins and themes from the dashboard, this feature will amaze you. It is much quicker than doing it manually.
wp theme install twentyeighteen
the above command will install the
wp theme activate twentyeighteen
Similarly, you can install and activate plugins using these commands
wp plugin install woocommerce wp plugin activate woocommerce
Updating plugins and Themes using WP-CLI
You can save our time to update the core and plugins by using this single line commands.
To update the core to the latest release, you can use this command.
wp core update
you can also install the specific version of WordPress
wp core update --version=4.7
you can also revert back to the previous version forcefully by amending this command at the end of above command
wp core update --version=4.4 --force
TO update the themes and plugins individually you can use this command
wp theme update twentyseventeen wp plugin update woocommerce
to update all you can use the below command
wp theme update --all wp plugin update --all
You can read about the WP-CLI commands. There are lots of commands to update post, comments, options, take DB backup etc. You can control the WordPress structure using the CLI and can save lots of time to implement on other projects.
Resources: WordPress CLI