Safe WordPress Install/Upgrade from Commandline using wp-cli

September 12, 2014 | By in HOWTOS, LINUX HOWTO
| Reply More

WordPress is a free and open source blogging tool and a content management system based on PHP and MySQL. It is the most popular blogging system in use on the web, started in 2003 with a single bit of code to enhance the typography of everyday writing and with just a few developers, it has grown to be the largest self-hosted blogging tool in the world, used on more than 60 million websites. Everything from the documentation to the code itself, was created by and for the community, it's an open source project, which means there are hundreds of people all over the world working on it. Features include simplicity, flexibility and ease of use, a plugin architecture and a template system.

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 its 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

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:

$ wp --info
$ 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.


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="" --title="Testing WP-CLI" --admin_user="admin" --admin_password="f00@password" --admin_email=""

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’s checksums to see if there are any changed files.

$ wp core verify-checksums

wordpress verify


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

wordpress plugin install

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


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.



Share This :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.