Administering WordPress from the Command Line (WP‑CLI)
The WordPress Command Line Interface (WP‑CLI) is a powerful tool that lets you manage WordPress directly from the terminal. On ruachost.com, WP‑CLI can be used to perform administrative tasks faster than through the dashboard, and it can be automated with cron jobs.
Why Use WP‑CLI?
Section titled “Why Use WP‑CLI?”- Perform WordPress tasks quickly without logging into the dashboard.
- Automate repetitive tasks with cron jobs.
- Manage plugins, themes, users, and databases efficiently.
- Useful for developers and system administrators familiar with Linux commands.
Getting Started with WP‑CLI
Section titled “Getting Started with WP‑CLI”- Access your server via SSH.
- Navigate to the directory where WordPress is installed.
- Run the following command to verify WP‑CLI is installed:
✅ If installed, you’ll see version and environment details.
wp --info⚙️ Common WP‑CLI Commands
Section titled “⚙️ Common WP‑CLI Commands”Managing Plugins
Section titled “Managing Plugins”-
List installed plugins:
Terminal window wp plugin list -
Install and activate a plugin:
Terminal window wp plugin install plugin-name --activate -
Update all plugins:
Terminal window wp plugin update --all
Updating WordPress
Section titled “Updating WordPress”-
Update WordPress core:
Terminal window wp core update -
Update database after core update:
Terminal window wp core update-db -
Check current WordPress version:
Terminal window wp core version
Database Management
Section titled “Database Management”-
Export database:
Terminal window wp db export -
Import database:
Terminal window wp db import backup.sql -
Optimize database:
Terminal window wp db optimize -
Repair database:
Terminal window wp db repair
User Management
Section titled “User Management”-
List all users:
Terminal window wp user list -
Update a user password:
Terminal window wp user update username --user_pass=newpassword
⚙️ Options & Settings
Section titled “⚙️ Options & Settings”-
Update admin email:
Terminal window wp option update admin_email user@example.com -
Retrieve custom login URL:
Terminal window wp option get rwl_page
Automating with Cron Jobs
Section titled “Automating with Cron Jobs” You can schedule WP‑CLI commands using cron jobs. For example:-
Daily database backup at 2:15 AM:
Terminal window 15 2 * * * cd /home/username/public_html; /usr/bin/wp db export >/dev/null 2>&1 -
Daily WordPress update at 3:15 AM:
Important Notes
Section titled “Important Notes”- WP‑CLI requires basic knowledge of the Linux command line.
- Always back up your site before running update or database commands.
- Some commands may not work outside the WordPress installation directory.
- Test cron jobs carefully to avoid unintended changes.