# Administering WordPress from the command line (WP-CLI)

> Use WP-CLI over SSH to manage WordPress plugins, themes, users and updates from the command line and automate tasks with cron.

Source: https://helpcenter.ruachost.com/wordpress/guides/administering-wordpress-from-the-command-line-wpcli/

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?

- 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

1. **Access your server** via SSH.
2. Navigate to the directory where WordPress is installed.
3. Run the following command to verify WP‑CLI is installed:

✅ If installed, you’ll see version and environment details.

```bash
wp --info
```

## ⚙️ Common WP‑CLI Commands

### Managing Plugins

- List installed plugins:

  ```bash
  wp plugin list
  ```
- Install and activate a plugin:

  ```bash
  wp plugin install plugin-name --activate
  ```
- Update all plugins:

  ```bash
  wp plugin update --all
  ```

  ```
  ```

### Updating WordPress

- Update WordPress core:

  ```bash
  wp core update
  ```
- Update database after core update:

  ```bash
  wp core update-db
  ```

  ```
  ```
- Check current WordPress version:

  ```bash
  wp core version
  ```

### Database Management

- Export database:

  ```bash
  wp db export
  ```
- Import database:

  ```bash
  wp db import backup.sql
  ```
- Optimize database:

  ```bash
  wp db optimize
  ```
- Repair database:

  ```bash
  wp db repair
  ```

### User Management

- List all users:

  ```bash
  wp user list
  ```
- Update a user password:

  ```bash
  wp user update username --user_pass=newpassword
  ```

### ⚙️ Options & Settings

- Update admin email:

  ```bash
  wp option update admin_email user@example.com
  ```
- Retrieve custom login URL:

  ```bash
  wp option get rwl_page
  ```

## Automating with Cron Jobs

     You can schedule WP‑CLI commands using cron jobs. For example:

- Daily database backup at 2:15 AM:

  ```bash
  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

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