WP-CLI is the official command line tool which allows to manage WordPress web sites from the command prompt. Updates can be performed, backups can be generated, new posts can be published and most of the admin actions can be performed with a set of commands.
WP command line interface use to complete admin tasks like upgrades, database backup creation, plugins and themes installations and removals, publishing and deleting posts, changing site’s URL settings and getting help on chosen commands.
Note that, SSH access is mandatory to use WP CLI commands. Before using it check whether the WP CLI is installed at your hosting server or machine.
How to check :
wp –version [ It will show the wp cli version installed ]
If not installed, how to install it :
Before installing WP-CLI, please make sure the environment meets the minimum requirements:
- UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment.
- PHP 5.4 or later
- WordPress 3.7 or later. Versions older than the latest WordPress release may have degraded functionality
If above points satisfied, please follow the steps : Reference URL : https://wp-cli.org/
[ download the wpcli phar ]
php wp-cli.phar –info [ check whether the phar file is working ]
chmod +x wp-cli.phar [ change permission ]
sudo mv wp-cli.phar /usr/local/bin/wp [ move to global folder ]
wp –info [ to check the installation ]
Now WP CLI is ready to install.
How to setup a WordPress website using WP CLI :
** Assuming few primary requirements are already there. Like MySQL, PHP and etc.
- Go to the Installation folder
- wp core download [ it will download the latest version ]
- wp core download –version=4.5.1 [ you can install any specified version if required ]
- wp core config –dbname=<databasename> –dbuser=<database username> –dbpass=<database password> –dbhost=<database hostname> [ it will generate the wp-config.php file with the specified settings.
- wp db create [ it will create db in the name you specified in last command ]
- wp core install –url=”studio.0effortthemes.com” –title=”Studio” –admin_user=”<admin username>” –admin_password=”<admin password>” –admin_email=”<admin email>” [ It will install WordPress at your specified URL, to check visit the URL ] **It will activate the default theme like Twenty Seventeen or else.
- wp theme delete twentyfifteen [ Delete unused themes ]
- wp plugin install plugin-slug [ Plugin should be hosted to wordpress.org ]
- wp plugin deactivate plugin-slug [ Deactivate the plugin ]
- wp plugin delete plugin-slug [ Delete the plugin ]
- wp rewrite structure ‘/%postname%/’ [ Rewrite the permalink structure ]***.htaccess file should be writable
- wp rewrite flush –hard [ To clear cache after setting up the site ]
On next part of this article we will discuss on the Database part of the WP CLI, and how the DB has been taken backup. How it can be used to easy setup in remote server from any repository.