diff --git a/scripts/install_redis.sh b/scripts/install_redis.sh index 83ba052..ba8103c 100644 --- a/scripts/install_redis.sh +++ b/scripts/install_redis.sh @@ -314,15 +314,20 @@ step_wp_object_cache() { return 0 fi - # Guard: WP-CLI available - if ! command -v wp >/dev/null 2>&1; then - warning "WP-CLI not found — skipping WP object cache config. Install WP-CLI first." + # Guard: WP-CLI available — resolve full path so sudo -u retains it + local wp_bin + for _wp in "/usr/local/bin/wp" "/usr/bin/wp" "/home/litespeed/bin/wp"; do + if [ -x "$_wp" ]; then wp_bin="$_wp"; break; fi + done + [ -z "${wp_bin:-}" ] && wp_bin=$(command -v wp 2>/dev/null || echo "") + if [ -z "${wp_bin:-}" ]; then + warning "WP-CLI not found — skipping WP object cache config. Expected at /usr/local/bin/wp" return 0 fi - # Guard: LiteSpeed Cache plugin active (run as litespeed to get correct WP context) + # Guard: LiteSpeed Cache plugin active (run as litespeed with full wp path) local plugin_status - plugin_status=$(sudo -u "$WEB_USER" -s wp plugin is-active litespeed-cache --path="$WP_ROOT" 2>/dev/null && echo "active" || echo "inactive") + plugin_status=$(sudo -u "$WEB_USER" "$wp_bin" plugin is-active litespeed-cache --path="$WP_ROOT" 2>/dev/null && echo "active" || echo "inactive") if [[ "$plugin_status" != "active" ]]; then warning "LiteSpeed Cache plugin is not active in WordPress — skipping object cache config." warning "Activate it at: WordPress Admin > Plugins > LiteSpeed Cache" diff --git a/scripts/litespeed_metrics.sh b/scripts/litespeed_metrics.sh index 2589e9f..564cd30 100644 --- a/scripts/litespeed_metrics.sh +++ b/scripts/litespeed_metrics.sh @@ -5,12 +5,17 @@ # Find WP-CLI location WP_CLI_PATH="" -if [ -f "/home/litespeed/bin/wp" ]; then - WP_CLI_PATH="/home/litespeed/bin/wp" -elif command -v wp >/dev/null 2>&1; then - WP_CLI_PATH="wp" -else - echo '{"error": "WP-CLI not found. Please ensure WP-CLI is installed and accessible."}' +for _wp_candidate in "/usr/local/bin/wp" "/usr/bin/wp" "/home/litespeed/bin/wp"; do + if [ -x "$_wp_candidate" ]; then + WP_CLI_PATH="$_wp_candidate" + break + fi +done +if [ -z "$WP_CLI_PATH" ]; then + WP_CLI_PATH=$(command -v wp 2>/dev/null || echo "") +fi +if [ -z "$WP_CLI_PATH" ]; then + echo '{"error": "WP-CLI not found. Expected at /usr/local/bin/wp — run: which wp"}' exit 1 fi diff --git a/scripts/litespeed_update_settings.sh b/scripts/litespeed_update_settings.sh index 61e4492..ac30554 100644 --- a/scripts/litespeed_update_settings.sh +++ b/scripts/litespeed_update_settings.sh @@ -1,14 +1,19 @@ #!/bin/bash -# Check if WP-CLI is available -if [ ! -f "/home/litespeed/bin/wp" ]; then - echo "WP-CLI not found" +# Find WP-CLI binary +WP_CLI_PATH="" +for _wp in "/usr/local/bin/wp" "/usr/bin/wp" "/home/litespeed/bin/wp"; do + if [ -x "$_wp" ]; then WP_CLI_PATH="$_wp"; break; fi +done +[ -z "$WP_CLI_PATH" ] && WP_CLI_PATH=$(command -v wp 2>/dev/null || echo "") +if [ -z "$WP_CLI_PATH" ]; then + echo "WP-CLI not found. Expected at /usr/local/bin/wp" exit 1 fi # Function to run WP-CLI commands run_wp_command() { - /home/litespeed/bin/wp --path=/var/www/webroot/ROOT "$@" + "$WP_CLI_PATH" --path=/var/www/webroot/ROOT "$@" } # Check for correct number of arguments diff --git a/scripts/manage_litespeed.php b/scripts/manage_litespeed.php index 4af3449..0d747fc 100644 --- a/scripts/manage_litespeed.php +++ b/scripts/manage_litespeed.php @@ -61,7 +61,7 @@ function get_lsws_version() { // Find WP-CLI binary function find_wp_cli() { - $candidates = ['/home/litespeed/bin/wp', '/usr/local/bin/wp', '/usr/bin/wp']; + $candidates = ['/usr/local/bin/wp', '/usr/bin/wp', '/home/litespeed/bin/wp']; foreach ($candidates as $path) { if (file_exists($path) && is_executable($path)) { return $path; @@ -118,7 +118,7 @@ function toggle_cache($enable = true) { $wp_root = find_wp_root(); if (!$wp) { - return ['ok' => false, 'error' => 'WP-CLI not found. Check /home/litespeed/bin/wp or /usr/local/bin/wp']; + return ['ok' => false, 'error' => 'WP-CLI not found. Expected at /usr/local/bin/wp — run: which wp']; } if (!$wp_root) { return ['ok' => false, 'error' => 'WordPress not found at /var/www/webroot/ROOT'];