WP-CLI is a set of command-line tools for managing WordPress installations on Ubuntu or other Linux distributions. You can update plugins, set up multisite installs and much more from CLI, without using a web browser. Why it's safe? Most people use GUI options to install /update WordPress, so many cases it fails because of permission issues.
WordPress use webserver user for this purpose and if the required files/directories don't have permissions for webserver user, then it fails. Wp-cli command can be run as the user who own WordPress files/directories so its less likely to have issues. And command line update using wp-cli is pretty fast than using GUI method.
Installing WP-CLI on Linux
Installing wp-cli on Linux is pretty simple. Download the wp-cli.phar file using curl and move to respective folder.
Curl by default available on most Linux distributions. First download wp-cli.phar file:
# curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Next you can optionally move the file to /usr/local/bin so it will be easy to access and use, using the following commands:
# chmod +x wp-cli.phar # sudo mv wp-cli.phar /usr/local/bin/wp
And finally check if it works using either of this command (run with non root account):
$ wp --info or $ php wp-cli.phar --info
If the test fails , make sure phar is whitelisted in suhosin executor. You can add the below line in php.ini (/etc/php5/cli/php.ini) file.
You can see the install process below:
You can update WP-CLI by repeating the above installation steps or using following command.
$ sudo wp cli update
Installing WordPress using WP-CLI
After WP-CLI is installed on your system installing and configuring WordPress installations is made very easy. First we will assume you have a working Apache/MySQL/PHP installation on your system and your web root directory is “/var/www/html”, the installation just takes 4 commands.
First use the following command to download the latest WordPress files in the current directory:
$ wp core download
Next use the following commands to create the wp-config file and the database for your new WordPress installation, you will need to change the dbname, dbuser and dbpassword to the database and user that is available on your system:
$ wp core config --dbname=test --dbuser=root --dbpass=password $ wp db create
Finally, you will have to use the core install command to finish the installation setting the url, title, admin_user, admin_password and admin_email parameters to values that you wish to use:
$ wp core install --url="www.linoxide.com" --title="Testing WP-CLI" --admin_user="admin" --admin_password="f00@password" --admin_email="firstname.lastname@example.org"
Note: WP-cli recommend running commands as a user, if wish you can run as root with
Other Core operations
You can use wp-cli to check the current version of WordPress with this command:
$ wp core version
If you need to update WordPress or you need to check for updates you can use the following commands to do so:
$ wp core check-update $ wp core update $ wp core update-db
Another interesting command is verify-checksums, this will verify WordPress files against WordPress.org’s checksums to see if there are any changed files.
$ wp core verify-checksums
WP-CLI also makes installing and updating plugins very easy. First you can use the search option to search for an addon and then use the slug name in the table to install that plugin like this:
$ wp plugin search seo
$ wp plugin install seo-ultimate
$ wp plugin activate seo-ultimate
$ wp plugin deactivate seo-ultimate
$ wp plugin delete seo-ultimate
Using the update command you can also update any module to the latest version. You can either use the command as "plugin update pluginname" or just use it with the --all argument at it will check and update all plugins
$ wp plugin update --all
Working with themes is as easy as with plugins, to install a new theme you can also use the "theme search" option and then use the slug name with the install command to automatically install it like this:
$ wp theme search red $ wp theme install graphene
As with plugins you can either update themes individually with the "theme update themename" command or use the --all flag to check and update all themes like this:
$ wp theme update --all
WP-CLI is a simple yet powerful utility that can help you manage WordPress installation in a simple manner, you can also add various tasks to cron so it automatically checks for updates, it is a simple yet versatile utility.