WordPress and the Command Line

These days there are often WordPress apps on the control panel of hosting providers that enable you to install WordPress easily with a click. You can install and run WordPress entirely by FTP/SFTP and the admin dashboard, but this can be slow. However, if you are comfortable with the Linux command line, you can install WordPress, themes, and plugins at a lightning fast speed. This is particularly useful if you are moving from one hosting company to another and you have more than one WordPress blog to move at the same time.

Installing WordPress from the Command Line

Sometimes SFTPing to a host can be very slow. WordPress is made up of so many individual files that uploading everything when installing or updating can take a very long time.

This method is very quick and snappy way to download the latest version of WordPress when you are initially installing your blog…

wget http://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz

WP CLI

These commands install WP-CLI…

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

You can do this from anywhere because the three lines are 1) download, 2) change permissions and 3) move.

If you install WP-CLI before installing WordPress you can even install WordPress with WP-CLI, see wp core install

wp core download –locale=nl_NL
wp core install –url=example.com –title=Example –admin_user=supervisor –admin_password=strongpassword –[email protected]
wp core version

The 3 lines are 1) download, 2) install and 3) check the version of WordPress that is installed.

Installing Plugins

Assuming you have already set up the WordPress blog (wp-config.php and database), you can then install and activate multiple plugins very easily like this…

wp plugin install wordpress-seo jetpack post-volume-stats add-target-fixer –activate

Another use might be that you can easily de-activate plugins if you ever have problems logging in…

wp plugin deactivate plugin-name

Search and Replace

One thing that you cannot do with SFTP and the WordPress admin dashboard is a sitewide search and replace. There are probably plugins that will help you do this, but it is made very easy with WP-CLI…

wp search-replace oldstring newstring

The --dry-run flag also helps you to see what you’re about to change before you change it.

Updating WordPress

Perhaps the most useful function of WP-CLI for me is the ability to update WordPress very easily and quickly. This is all it takes…

wp core update

Summary

For more info see the docs at WP-CLI.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.