How to Install WordPress Command Line using WP-CLI

WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, 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

Installing WP-CLI is pretty simple using curl like this:

# 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

Note :
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.

suhosin.executor.include.whitelist="phar"

You can see the install process below:

wp-cli install

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="[email protected]" --admin_email="[email protected]"

wordpress install

new wordpress page

Other Core operations

You can use wp-cli to check the current version of WordPress with this command:

$ wp core version

wordpress 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 update
$ wp core update-db

wordpress update

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

wordpress verify

Plugins

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:

Search plugin

$ wp plugin search seo

wordpress plugin install

Install plugin

$ wp plugin install seo-ultimate

Activate plugin

$ wp plugin activate seo-ultimate

Deactivate plugin

$ wp plugin deactivate seo-ultimate

Delete plugin

$ 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

wordpress plugin update

Themes

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

wordpress-theme-install

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

wordpress-theme-update

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.

Adrian Dinu 9:56 am

About Adrian Dinu

I’ve been a Linux enthusiast since 1998 and been working as a Linux Admin in the past 8 years with a lot of love for computers and networks.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.