Use this as a template by copying the current template and adding this code to that. Rename that template to your liking, and choose it in the UI for a site as a template.
I’m assuming you are using PHP Redis extension and not predis. Also are you not using W3 Total Cache to configure Redis from the dashboard without the need to do edit the wp-config file?
yeah.. i figured that duplicating the WordPress installer file and modifying it to include the desired config will be the way to go forward. Here’s a suggestion from Google’s Gemini 2.5 Pro.
Please note this isn’t tested yet by me - it’s a suggestion by Gemini Pro 2.5.
Go to the very end of the setupApplication function. Find the final closing curly brace `}` of that function, which is right before the final `}` of the class.
Add the following code **just before** that final closing brace:
```php
// --- START: Custom Redis Configuration ---
// Define the path to wp-config.php
$wp_config_path = $target->getDocRoot() . '/wp-config.php';
// Create the multi-line string for the config.
// We get the domain from the $target object.
$redis_config = <<<EOT
// Redis Object Cache Settings
define('WP_REDIS_SCHEME', 'unix');
define('WP_REDIS_PATH', '/var/run/redis/redis.sock');
define('WP_REDIS_PREFIX', '{$target->getDomain()->__toString()}');
define('WP_REDIS_PASSWORD', 'ABbv8S68DDeYksD');
EOT;
// Append the configuration to the file
file_put_contents($wp_config_path, $redis_config, FILE_APPEND);
// Install and activate the Redis plugin using Hestia's wp-cli wrapper
$this->appcontext->runWp($options['php_version'], [
'plugin',
'install',
'redis-cache',
'--activate',
'--path=' . $target->getDocRoot(),
]);
// --- END: Custom Redis Configuration ---
}
}
```
Your final few lines of the file should look like the snippet above. Notice you are adding the code just above the `}` that closes the `setupApplication` function.
What This New Code Does
This code is specifically tailored to the file you provided:
$target->getDocRoot(): It correctly gets the installation path from the $target object, which is available inside the function.
$target->getDomain()->__toString(): It dynamically gets the domain name for the new site and uses it for the Redis prefix.
file_put_contents(...): This remains the best way to append your settings to the newly created wp-config.php.
$this->appcontext->runWp(...): This uses Hestia’s built-in function to properly run the wp-cli command to install and activate the Redis plugin.