A secure, fast, and modular WP-CLI management system for maintaining multiple WordPress sites efficiently. This toolkit provides automated updates, database optimization, and maintenance operations across all your WordPress installations.
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- 5.1 Basic Syntax
- 5.2 Operation Modes
- 5.3 Options
- 5.4 Examples
- How It Works
- 6.1 User Detection
- 6.2 Safe Execution
- 6.3 Logging System
- Troubleshooting
- 7.1 Common Issues
- 7.2 Debug Mode
- Contributing
- License
- Acknowledgments
- Author & Support
- Multi-site Management: Automate maintenance across multiple WordPress installations
- Flexible Operation Modes: Choose specific maintenance tasks or run comprehensive updates
- Smart User Detection: Automatically determines correct system users for WP-CLI operations
- Comprehensive Logging: Detailed execution logs with color-coded output
- Automatic Discovery: Find WordPress installations automatically with the included discovery script
- Safe Operations: Built-in safety checks and error handling
- Database Optimization: Automatic database repair and optimization
- Cron Management: Run WordPress cron events efficiently
- Astra Pro Support: Specialized handling for Astra Pro plugin with license management
- Detailed Error Logging: Comprehensive error tracking in
wp_cli_errors.log
- Operating System: Linux (tested on CentOS, Ubuntu, Debian)
- Shell: Bash 4.0 or higher
- Permissions: Root access (for user switching)
- Dependencies:
- WP-CLI installed at
/usr/local/bin/wp - WordPress 3.7 or higher
- Standard GNU core utilities
- WP-CLI installed at
Clone the repository or download the scripts directly:
git clone https://github.com/paulmann/Bash_WP-CLI_Update.git
cd Bash_WP-CLI_UpdateImportant: Make both scripts executable:
chmod +x Bash_WP-CLI_Update.sh
chmod +x Find_WP_Senior.shCheck that the shebang lines at the top of each script point to correct shell paths:
- Bash_WP-CLI_Update.sh: Should have
#!/usr/bin/env bash - Find_WP_Senior.sh: Should have
#!/bin/bash
Update if necessary for your system configuration.
Ensure WP-CLI is installed at the expected location:
which wp
# Should return: /usr/local/bin/wpIf not installed, follow WP-CLI installation instructions.
Run the discovery script to automatically find WordPress installations:
./Find_WP_Senior.shThis will create a wp-found.txt file with paths to all discovered WordPress installations.
If you prefer manual configuration, create or edit wp-found.txt:
nano wp-found.txtAdd one WordPress root directory per line:
/var/www/site1.com
/var/www/site2.com
/var/www/site3.com
For Astra Pro plugin support, configure your license key in the main script:
# Edit the script and set your Astra Pro license key
nano Bash_WP-CLI_Update.sh
# Locate and update the ASTRA_KEY constant:
readonly ASTRA_KEY="YOUR_ACTUAL_LICENSE_KEY_HERE"./Bash_WP-CLI_Update.sh [MODE] [OPTIONS]| Mode | Short | Description |
|---|---|---|
--full |
-f |
Complete maintenance (core, plugins, themes, DB optimize/repair, cron) |
--core |
-c |
Update WordPress core only |
--plugins |
-p |
Update all plugins |
--themes |
-t |
Update all themes |
--db-optimize |
-d |
Optimize and repair database |
--db-fix |
-x |
Repair database only |
--cron |
-r |
Run due cron events |
--astra |
-s |
Update Astra Pro plugin with license activation |
| Option | Short | Description |
|---|---|---|
--DEBUG |
-D |
Enable detailed debug logging |
Update all plugins across all sites:
./Bash_WP-CLI_Update.sh --plugins
# or using short option
./Bash_WP-CLI_Update.sh -pRun complete maintenance with debug output:
./Bash_WP-CLI_Update.sh --full --DEBUG
# or using short options
./Bash_WP-CLI_Update.sh -f -DOptimize databases only:
./Bash_WP-CLI_Update.sh --db-optimizeRun WordPress cron events:
./Bash_WP-CLI_Update.sh --cronUpdate Astra Pro plugin with license management:
./Bash_WP-CLI_Update.sh --astraThe script automatically determines the correct system user for each WordPress installation by checking:
- File owner of
wp-config.php - Directory owner of WordPress root
- Path structure patterns
- DB_USER from wp-config.php (fallback)
- Runs WP-CLI commands as the correct system user
- Includes proper environment variables
- Skips problematic plugins during updates
- Provides comprehensive error handling
Structured logging with timestamps and color-coded console output:
INFO- General operation informationSUCCESS- Completed operationsWARNING- Non-critical issuesERROR- Operation failuresDEBUG- Detailed debugging information
Detailed error logging for troubleshooting:
- Complete command context
- Full command output
- Exit codes and error details
- Timestamped error events
Script stops after "Processing site":
- Check that WP-CLI is installed at
/usr/local/bin/wp - Verify the WordPress user exists and has proper permissions
- Run with
--DEBUGflag for detailed output
Permission denied errors:
- Ensure scripts are executable:
chmod +x *.sh - Run as root user for proper user switching
WP-CLI not found:
- Install WP-CLI globally or update the path in the script
- Verify installation with
wp --info
Astra Pro license errors:
- Ensure
ASTRA_KEYis set to your actual license key in the script - Verify Astra Pro plugin is installed and active
- Check error log for detailed license activation issues
For detailed troubleshooting, use debug mode:
./Bash_WP-CLI_Update.sh --cron --DEBUGThis provides:
- Step-by-step execution details
- Command output and exit codes
- User detection process information
- Environment variable settings
Check the detailed error log for in-depth analysis:
tail -f wp_cli_errors.logWe welcome contributions! Please feel free to submit pull requests, report bugs, or suggest new features.
- Follow existing code style and structure
- Add appropriate error handling
- Include debug information for new features
- Update documentation for changes
- Test changes thoroughly before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
- WP-CLI Team for the excellent command-line interface
- WordPress Community for continuous improvement and updates
- Astra Team for the wonderful theme and plugin ecosystem
- Contributors who help maintain and improve this tool
Mikhail Deynekin
- π Website: deynekin.com
- π§ Email: mid1977@gmail.com
- π GitHub: @paulmann
- π Documentation: Read this README thoroughly
- π Bug Reports: Open an issue
- π‘ Feature Requests: Request features
- π¬ Questions: Check Discussions
Note: Always test maintenance scripts in a staging environment before deploying to production.