Join the community today
Become a Member

Wordpress Preview: addons/wp-redis-object-cache-setup.sh Wordpress Redis Object Cache Plugin Installer

Discussion in 'Blogs & CMS usage' started by eva2000, Sep 22, 2020.

  1. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,312
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,994
    Local Time:
    10:35 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Working on a new Centmin Mod 123.09beta01 addon this can install and configure Redis Object Cache Wordpress plugin as well as uninstall/remove it from Centmin Mod generated Nginx vhost based Wordpress sites. The addon will be at addons/wp-redis-object-cache-setup.sh eventually once I make the addon publicly available :)

    The addon won't install Redis server itself, but check if Redis server is installed and running before proceeding. If Redis server isn't detected as running, then the addon will abort and exit the process.

    What is Redis Object Cache Wordpress plugin?



    Wordpress object caching basically caches the MySQL query results for subsequent MySQL query cache read offloading. This reduces MySQL read based query load on the MySQL server.

    Official Redis Object Cache WP plugin description.

    Usage



    Example usage shows only 2 command options for enable and disable where they take several arguments.
    Code (Text):
    ./wp-redis-object-cache-setup.sh
    Usage:
    
    ./wp-redis-object-cache-setup.sh enable domain.com redis_db_number timeout maxttl 127.0.0.1:6379
    ./wp-redis-object-cache-setup.sh enable domain.com 2 2 3600 127.0.0.1:6379
    
    ./wp-redis-object-cache-setup.sh disable domain.com
    


    Install & Enable Redis Object Cache WP Plugin



    For example to install, activate and configure Redis object caching for Wordpress site on cache-enabler.domain.com with redis database number = 2 with Redis timeouts set to 2 seconds and Redis cache TTL set at 3600 seconds (1hr) using TCP port 6379 listening Redis server on 127.0.0.1.
    Code (Text):
    cd /usr/local/src/centminmod
    ./wp-redis-object-cache-setup.sh enable cache-enabler.domain.com 2 2 3600 127.0.0.1:6379

    example output
    Code (Text):
    cd /usr/local/src/centminmod
    ./wp-redis-object-cache-setup.sh enable cache-enabler.domain.com 2 2 3600 127.0.0.1:6379
    Configuring redis object cache plugin wp-login.php settings for:
    /home/nginx/domains/cache-enabler.domain.com/public
    Installing Redis Object Cache (2.0.13)
    Downloading installation package from https://downloads.wordpress.org/plugin/redis-cache.2.0.13.zip...
    Using cached file '/root/.wp-cli/cache/plugin/redis-cache-2.0.13.zip'...
    Unpacking the package...
    Installing the plugin...
    Plugin installed successfully.
    Activating 'redis-cache'...
    Plugin 'redis-cache' activated.
    Success: Installed 1 of 1 plugins.
    Success: Added the constant 'WP_REDIS_HOST' to the 'wp-config.php' file with the value '127.0.0.1'.
    Success: Added the constant 'WP_REDIS_PORT' to the 'wp-config.php' file with the raw value '6379'.
    Success: Added the constant 'WP_REDIS_DATABASE' to the 'wp-config.php' file with the raw value '2'.
    Success: Added the constant 'WP_REDIS_TIMEOUT' to the 'wp-config.php' file with the raw value '2'.
    Success: Added the constant 'WP_REDIS_READ_TIMEOUT' to the 'wp-config.php' file with the raw value '2'.
    Success: Added the constant 'WP_REDIS_MAXTTL' to the 'wp-config.php' file with the raw value '3600'.
    Success: Updated object cache drop-in and enabled Redis object cache.
    Restarting nginx (via systemctl):  [  OK  ]
    Restarting php-fpm (via systemctl) [  OK  ]
    
    Configured wp-login.php settings:
    
    define( 'WP_REDIS_HOST', '127.0.0.1' );
    define( 'WP_REDIS_PORT', 6379 );
    define( 'WP_REDIS_DATABASE', 2 );
    define( 'WP_REDIS_TIMEOUT', 2 );
    define( 'WP_REDIS_READ_TIMEOUT', 2 );
    define( 'WP_REDIS_MAXTTL', 3600 );
    
    Installed & activated redis object cache plugin for:
    /home/nginx/domains/cache-enabler.domain.com/public
    

    So wp-config.php now have the following Redis object cache plugin settings added for
    Code (Text):
    define( 'WP_REDIS_HOST', '127.0.0.1' );
    define( 'WP_REDIS_PORT', 6379 );
    define( 'WP_REDIS_DATABASE', 2 );
    define( 'WP_REDIS_TIMEOUT', 2 );
    define( 'WP_REDIS_READ_TIMEOUT', 2 );
    define( 'WP_REDIS_MAXTTL', 3600 );
    


    wp-redis-object-cache-settings-01.png
    wp-redis-object-cache-settings-02.png
    wp-redis-object-cache-settings-03.png

    Disable & Uninstall Redis Object Cache WP Plugin



    To disable and remove only need to use disable option and pass the domain name of the Centmin Mod Nginx vhost Wordpress site i.e. cache-enabler.domain.com
    Code (Text):
    cd /usr/local/src/centminmod
    ./wp-redis-object-cache-setup.sh disable cache-enabler.domain.com
    

    Code (Text):
    cd /usr/local/src/centminmod
    ./wp-redis-object-cache-setup.sh disable cache-enabler.domain.com
    Remove redis object cache plugin from Wordpress installation at:
    /home/nginx/domains/cache-enabler.domain.com/public
    Success: Deleted the constant 'WP_REDIS_HOST' from the 'wp-config.php' file.
    Success: Deleted the constant 'WP_REDIS_PORT' from the 'wp-config.php' file.
    Success: Deleted the constant 'WP_REDIS_DATABASE' from the 'wp-config.php' file.
    Success: Deleted the constant 'WP_REDIS_TIMEOUT' from the 'wp-config.php' file.
    Success: Deleted the constant 'WP_REDIS_READ_TIMEOUT' from the 'wp-config.php' file.
    Success: Deleted the constant 'WP_REDIS_MAXTTL' from the 'wp-config.php' file.
    Success: Object cache disabled.
    Plugin 'redis-cache' deactivated.
    Success: Deactivated 1 of 1 plugins.
    Uninstalled and deleted 'redis-cache' plugin.
    Success: Uninstalled 1 of 1 plugins.
    Restarting nginx (via systemctl):  [  OK  ]
    Restarting php-fpm (via systemctl) [  OK  ]
    
    Disabled & Uninstalled redis object cache plugin for:
    /home/nginx/domains/cache-enabler.domain.com/public
    
     
    Last edited: Sep 22, 2020