Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:cache:redis [2017/08/23 19:49] Eric Leu [Install Redis PHP extension] |
litespeed_wiki:cache:redis [2020/11/14 16:28] (current) Lisa Clarke Redirect to new Documentation Site |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How to setup Redis with LSWS for WordPress ===== | + | ~~REDIRECT>https://docs.litespeedtech.com/lscache/lscwp/admin/~~ |
- | Redis is an open source, in-memory data structure store, used as a database, cache and message broker. [[https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache | LSCache]] is the world's fastest full page caching. So it's a good way to have both of them on your server. | + | |
- | This guide is valid for both no Control Panel and with control panels. | + | |
- | + | ||
- | ==== Install Redis daemon ==== | + | |
- | For both cPanel and Native setup on CentOS 7: | + | |
- | - Add the EPEL repository: \\ <code>yum install epel-release </code> | + | |
- | - Install Redis: \\ <code>yum install redis</code> | + | |
- | - Start Redis: \\ <code>systemctl start redis</code> | + | |
- | + | ||
- | ==== Install Redis PHP extension ==== | + | |
- | The phpredis extension provides an API for communicating with the Redis key-value store. | + | |
- | + | ||
- | === With cPanel === | + | |
- | - Installing the Redis PHP extension for all available versions of PHP: \\ <code>for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do | + | |
- | cd ~ | + | |
- | wget -O redis.tgz https://pecl.php.net/get/redis | + | |
- | tar -xvf redis.tgz | + | |
- | cd ~/redis* || exit | + | |
- | /opt/cpanel/ea-php"$phpver"/root/usr/bin/phpize | + | |
- | ./configure --with-php-config=/opt/cpanel/ea-php"$phpver"/root/usr/bin/php-config | + | |
- | make && make install | + | |
- | echo 'extension=redis.so' > /opt/cpanel/ea-php"$phpver"/root/etc/php.d/redis.ini | + | |
- | rm -rf ~/redis* | + | |
- | done | + | |
- | + | ||
- | /scripts/restartsrv_httpd | + | |
- | /scripts/restartsrv_apache_php_fpm</code> | + | |
- | - Check Redis: \\ <code>for phpver in $(ls -1 /opt/cpanel/ |grep php | sed 's/ea-php//g') ; do | + | |
- | echo "PHP $phpver" ; /opt/cpanel/ea-php$phpver/root/usr/bin/php -i |grep "Redis Support" | + | |
- | done</code> Output should be:<code>PHP 55 | + | |
- | Redis Support => enabled | + | |
- | PHP 56 | + | |
- | Redis Support => enabled | + | |
- | PHP 70 | + | |
- | Redis Support => enabled </code> | + | |
- | + | ||
- | * Note: | + | |
- | * Checking newest PHP redis version [[https://pecl.php.net/package/redis | here]] | + | |
- | * For More description please follow [[https://github.com/phpredis/phpredis/ | Git]] | + | |
- | + | ||
- | === Without control panel === | + | |
- | - Add the litespeed repository: \\ <code>rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm</code> | + | |
- | - List the litespeed Redis PHP extension \\ <code>yum list | awk '/lsphp/&&/redis/'</code> | + | |
- | - Install PHP version depends on which version you are using: \\ <code>yum -y install lsphp71-pecl-redis</code> | + | |
- | + | ||
- | + | ||
- | ==== Verify the Installation ==== | + | |
- | - Verify that Redis is running with redis-cli: \\ <code>redis-cli ping</code> \\ If Redis is running, it will return: <code>PONG</code> | + | |
- | - Verify by using LiteSpeed default PHP info page http://Server_IP:8088/phpinfo.php: \\ {{:litespeed_wiki:cache:redis-1.png?700|}} | + | |
- | + | ||
- | ==== Try the redis-benchmark utility==== | + | |
- | - A typical example would be: \\ <code> redis-benchmark -q -n 100000 </code> Output: <code>PING_INLINE: 31826.86 requests per second | + | |
- | PING_BULK: 31595.58 requests per second | + | |
- | SET: 33568.31 requests per second | + | |
- | GET: 31908.10 requests per second | + | |
- | INCR: 32647.73 requests per second | + | |
- | LPUSH: 31220.73 requests per second | + | |
- | RPUSH: 31565.66 requests per second | + | |
- | LPOP: 31555.70 requests per second | + | |
- | + | ||
- | </code> | + | |
- | - If you want to run one million SET operations, using a random key for every operation out of 100k possible keys, you can use the following command line: \\ <code>redis-cli flushall | + | |
- | redis-benchmark -t set -r 100000 -n 1000000</code> Output: <code>====== SET ====== | + | |
- | 1000000 requests completed in 32.43 seconds | + | |
- | 50 parallel clients | + | |
- | 3 bytes payload | + | |
- | keep alive: 1 | + | |
- | 99.98% <= 10 milliseconds | + | |
- | 99.99% <= 11 milliseconds | + | |
- | 99.99% <= 12 milliseconds | + | |
- | 100.00% <= 17 milliseconds | + | |
- | 30833.75 requests per second | + | |
- | </code> | + | |
- | + | ||
- | * Note: | + | |
- | * For more redis benchmark information, please refer [[https://redis.io/topics/benchmarks | here]] | + | |
- | ==== Integrate WordPress with Redis ==== | + | |
- | - WordPress install **Redis Object Cache** Plugin \\ {{:litespeed_wiki:cache:redis-5.png?400|}} | + | |
- | - Activate and click **Enable Object Cache** button \\ {{:litespeed_wiki:cache:redis-2.png?600|}} | + | |
- | - Confirm Status is ''Connected'' \\ {{:litespeed_wiki:cache:redis-3.png?600|}} | + | |
- | - Confirm Diagnostics shows Redis with version \\ {{:litespeed_wiki:cache:redis-6.png?600|}} | + | |
- | - Edit ''wp-config.php'' and at the end of the ''Authentication Unique Keys and Salts'' section, add the following lines: | + | |
- | - <nowiki>define('WP_CACHE_KEY_SALT', 'string');</nowiki> | + | |
- | - <nowiki>define('WP_CACHE', true);</nowiki> | + | |
- | - Restart LSWS \\ <code>service lsws restart</code> | + | |
- | - Test WordPress is communicating with Redis by monitor command: \\ <code> redis-cli monitor </code> {{:litespeed_wiki:cache:redis-4.png?300|}} | + | |
- | + | ||
- | + | ||
- | ==== Other Settings==== | + | |
- | * If you want to setup Master-Slave Replication, you may need to enable firewall for port 6379 <code>firewall-cmd --permanent --zone=public --add-port=6379/tcp | + | |
- | firewall-cmd --reload </code> | + | |
- | * To automatically start Redis on boot: \\ <code>systemctl enable redis</code> | + | |
- | * For disk persistence, you can set ''/etc/redis.conf'': | + | |
- | * appendonly yes | + | |
- | * appendfsync everysec | + | |
- | * More Redis Security information please follow [[https://redis.io/topics/security | here]] | + | |
- | + | ||
- | + |