Discover Centmin Mod today
Register Now

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

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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/addons
    ./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/addons
    ./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/addons
    ./wp-redis-object-cache-setup.sh disable cache-enabler.domain.com
    

    Code (Text):
    cd /usr/local/src/centminmod/addons
    ./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: Jun 7, 2022
  2. Matt Williams

    Matt Williams WordPress Fanatic

    537
    104
    43
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +157
    Local Time:
    12:40 PM
    latest
    10
    Has this been completed or still working on it?
    Also, would be nice to have Redis Object Cache ( database cache ) + Nginx Helper Redis ( Page cache ) to install both together for menu option #22
     
  3. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    That is the eventual goal after the preview setup script testing is completed - which isn't right now.
     
  4. Jay Chen

    Jay Chen Active Member

    181
    60
    28
    Sep 10, 2017
    Ratings:
    +116
    Local Time:
    12:40 PM
    I just discover this thread, this is amazing. Is the addon ready for testing? I can help
     
  5. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Pretty close though haven't decided some things yet as out of the box Redis server is only pre-configured with databases 0 to 14 for 15 databases. So if you are using one Redis database per Wordpress site, if you have a lot of Wordpress sites, you'll need more that the pre-configured amount.

    For most folks right now it's pretty easy to just manually install the Redis Object cache plugin and pluck in the following in wp-config.php 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 );
    

    and that's it really!

    The tool is more if you're automating Wordpress installs and need to automate Redis Object cache plugin install + configuration.
     
  6. Jon Snow

    Jon Snow Active Member

    835
    170
    43
    Jun 30, 2017
    Ratings:
    +256
    Local Time:
    1:40 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Is this the same as Redis Object Cache?

    Can we just install the plugin through Wordpress and add this to wp-config?

    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 );
     
  7. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yup same plugin and adding those settings to wp-config is correct provided your redis server is installed and running. This addon just automates that manual process :)
     
  8. Jon Snow

    Jon Snow Active Member

    835
    170
    43
    Jun 30, 2017
    Ratings:
    +256
    Local Time:
    1:40 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Already did that.

    Would I have to do anything additional if I want to use this plugin for multiple Wordpress sites on the same server?
     
  9. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    You can optionally use a different redis database number for each - by default there's redis database numbers 0-15 for 16 databases as defined in /etc/redis/redis.conf config file

    You can edit that number of databases in /etc/redis/redis.conf and restart redis server
    Code (Text):
    grep -B2 -i '^databases ' /etc/redis/redis.conf 
    # a different one on a per-connection basis using SELECT <dbid> where
    # dbid is a number between 0 and 'databases'-1
    databases 16
    

    Code (Text):
    define( 'WP_REDIS_DATABASE', 2 );
    

    So if you purge/flush the redis database, you only are purging data to that Wordpress instance

    flush redis database 2
    Code (Text):
    redis-cli -n 2 flushall
    OK
    
     
  10. Jon Snow

    Jon Snow Active Member

    835
    170
    43
    Jun 30, 2017
    Ratings:
    +256
    Local Time:
    1:40 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    I assume it's something you recommend doing since it's optional?
     
  11. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yes I do it so you can flush entire redis database just for that Wordpress instance.
     
  12. quicksalad

    quicksalad Member

    228
    13
    18
    May 31, 2015
    Ratings:
    +20
    Local Time:
    11:10 PM
    will Redis Object Cache Plugin works even when using Cache Enabler in option 22?
     
  13. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yes it should :)
     
  14. quicksalad

    quicksalad Member

    228
    13
    18
    May 31, 2015
    Ratings:
    +20
    Local Time:
    11:10 PM
    Thanks @eva2000
    May I ask if the addon is completed? I'm using Memcached Object Cache and will try this one as I'm having trouble with it.
     
  15. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  16. BrianLT

    BrianLT New Member

    6
    0
    1
    Jan 19, 2025
    Ratings:
    +1
    Local Time:
    5:40 PM
    I see that redis come installed with the default PHP 8.3 installation.

    I previously tested Redis using a Unix socket (/path/of/redis/socket-file.sock) instead of the standard TCP connection (127.0.0.1:6379). The result was about a 30% performance improvement with the socket connection.

    You can try this yourself using the WordPress Hosting Benchmark Tool plugin, which runs persistent object cache tests. In my case, my score improved from 7.1/10 to a perfect 10/10 when switching to the .sock connection.
     
  17. eva2000

    eva2000 Administrator Staff Member

    54,583
    12,224
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,793
    Local Time:
    3:40 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yup for Redis Unix sockets is faster though Centmin Mod defaults to TCP as most Web apps and users expect such. So leave reconfiguration of Redis to use Unix sockets up to end user. Also Unix sockets only allow connections inside the server and not remote so if you have Redis cluster or load balanced setups, you'd need TCP instead