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.

 
Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)

Powered by WHMCompleteSolution