Let us take a look at wp-cli in this post, this is a command line based and powerful WordPress management tool. Recently I published a series of posts on different ways to install and manage WordPress sites using command line tools. This post can be considered as an add-on to that post.
Introduction to wp-cli
wp-cli is a powerful command-line tool that allows you to manage your WordPress websites without using a web browser. From configuration to management, wp-cli can handle WordPress sites with aplomb. In the below sections, we will walk you through the process of installing wp-cli on a Virtual Private Server, configuring it for use, and managing your WordPress site.
Installing wp-cli on a VPS
Before you start, ensure that you have SSH access to your VPS. You can use this powerful wordpress management tool on a VPS that is already running WordPress. Here are the steps to install wp-cli:
Connect to Your Server: Using SSH, connect to your VPS. The command will look something like this:
$ ssh user@your_server_ip
Download wp-cli: Run the following command to download the w-pcli phar file to the home directory:
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Check if wp-cli is Working: You can check if wp-cli is working by running:
$php wp-cli.phar --info
If it’s working correctly, it will display information about the wp-cli version and other details.
Make wp-cli Executable: To make wp-cli executable from anywhere in the filesystem, you need to move it to the /usr/local/bin directory and rename it to wp. Use the following command:
$ sudo mv wp-cli.phar /usr/local/bin/wp
Verify the Installation: To verify that wp-cli is installed correctly, run:
$ wp --info
If it displays information about the wp-cli version, the installation was successful.
Installing WordPress using wp-cli
Create a MySQL database and user for WordPress:
mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Download and install WordPress using WP-CLI as mentioned above. Next, use the following commands to install WordPress using wp-cli
wp core config --dbname=wordpress --dbuser=wordpressuser --dbpass=password --dbhost=localhost --dbprefix=wp_
wp db create
wp core install --url=http://your_domain_or_ip --title=YourWebsiteTitle --admin_user=YourAdminUsername --admin_password=YourAdminPassword --admin_email=YourAdminEmail
These methods offer flexibility based on your preferences and requirements. Choose the one that best fits your setup and familiarity with tools.
Configuring wp-cli for Use
After installing wp-cli, you need to configure it to manage your WordPress site.
Navigate to Your WordPress Directory: Use the cd command to navigate to the directory where WordPress is installed. For example:
$ cd /var/www/html
Test wp-cli: Run the command wp core version. If wp-cli is correctly configured, it will return the version of WordPress installed on your server.
wp-cli – a powerful WordPress Management Tool
With wp-cli installed and configured, you can now use it to manage your WordPress site. Here are a few basic commands:
Update WordPress: Keep your WordPress installation up to date with the command
$ wp core update
Install and Activate Plugins: Install a new plugin and activate it using wp plugin install plugin-name –activate.
Update Plugins: Update all your plugins with
$ wp plugin update --all
Create a New User: Add a new user to your WordPress site with
$ wp user create username [email protected] –role=role
(Role can be editor, author, administrator, etc.)
Backup Your WordPress Database: Create a backup of your WordPress database with
$ wp db export
Key Takeaways
wp-cli is a valuable and a powerful wordpress management tool for anyone working with WordPress. Whether you’re a developer looking to streamline your workflow or an administrator trying to automate routine tasks, wp-cli is useful. With its extensive list of commands and capabilities, wp-cli makes it easy to manage your WordPress installation from the comfort of your own command line.
Links and Resources
Certainly! Here are the links to the first four items in my previous response:
1. Official Documentation
2. WP-CLI GitHub Repository
3. WP-CLI YouTube Channel and Twitter(X)
This post was published under the category Content Management Systems. This post was substantially updated on 19 Feb 2024.