Debian/Plesk: Install Redis, Memcache and APCU on Plesk + GnuPG for PHP 8.1

Debian/Plesk: Install Redis, Memcache and APCU on Plesk + GnuPG for PHP 8.1

In the following we will install Redis, Memcache, APCU and GnuPG for Plesk. The instructions can basically be applied to any PHP version.

First, of course, we need the appropriate PHP version of Plesk

apt-get install -y plesk-php74-dev plesk-php80-dev plesk-php81-dev
ln /bin/sed /usr/bin/sed #ggf necessary - test before with which sed path

After that we have to install some basics

apt-get update
apt-get install -y memcached 
apt-get install -y autoconf 
apt-get install -y automake 
apt-get install -y gcc 
apt-get install -y libmemcached-dev 
apt-get install -y libhashkit-dev 
apt-get install -y pkg-config 
apt-get install -y zlib1g-dev 
apt-get install -y make 
apt-get install -y libgpgme11-dev

Then we create the appropriate PHP modules with the following commands:

/opt/plesk/php/7.3/bin/pecl install apcu
/opt/plesk/php/7.4/bin/pecl install apcu
/opt/plesk/php/8.0/bin/pecl install apcu
/opt/plesk/php/8.1/bin/pecl install apcu
/opt/plesk/php/7.3/bin/pecl install redis
/opt/plesk/php/7.4/bin/pecl install redis
/opt/plesk/php/8.0/bin/pecl install redis
/opt/plesk/php/8.1/bin/pecl install redis
/opt/plesk/php/7.4/bin/pecl install gnupg
/opt/plesk/php/8.1/bin/pecl install gnupg
/opt/plesk/php/7.4/bin/pecl install memcached
/opt/plesk/php/8.1/bin/pecl install memcached

For the modules to be loaded, they must also be stored accordingly:

echo "extension=/opt/plesk/php/7.3/lib/php/modules/apcu.so" > /opt/plesk/php/7.3/etc/php.d/apcu.ini
echo "extension=/opt/plesk/php/7.4/lib/php/modules/apcu.so" > /opt/plesk/php/7.4/etc/php.d/apcu.ini
echo "extension=/opt/plesk/php/8.0/lib/php/modules/apcu.so" > /opt/plesk/php/8.0/etc/php.d/apcu.ini
echo "extension=/opt/plesk/php/8.1/lib/php/modules/apcu.so" > /opt/plesk/php/8.1/etc/php.d/apcu.ini
echo "extension=/opt/plesk/php/7.3/lib/php/modules/redis.so" > /opt/plesk/php/7.3/etc/php.d/redis.ini
echo "extension=/opt/plesk/php/7.4/lib/php/modules/redis.so" > /opt/plesk/php/7.4/etc/php.d/redis.ini
echo "extension=/opt/plesk/php/8.0/lib/php/modules/redis.so" > /opt/plesk/php/8.0/etc/php.d/redis.ini
echo "extension=/opt/plesk/php/8.1/lib/php/modules/redis.so" > /opt/plesk/php/8.1/etc/php.d/redis.ini
echo "extension=/opt/plesk/php/7.4/lib/php/modules/gnupg.so" > /opt/plesk/php/7.4/etc/php.d/gnupg.ini
echo "extension=/opt/plesk/php/8.1/lib/php/modules/gnupg.so" > /opt/plesk/php/8.1/etc/php.d/gnupg.ini
echo "extension=/opt/plesk/php/7.4/lib/php/modules/memcached.so" > /opt/plesk/php/7.4/etc/php.d/memcached.ini
echo "extension=/opt/plesk/php/8.1/lib/php/modules/memcached.so" > /opt/plesk/php/8.1/etc/php.d/memcached.ini

After that we need to re-read the PHP config and restart the services:

plesk bin php_handler --reread
service plesk-php73-fpm restart
service plesk-php74-fpm restart
service plesk-php80-fpm restart
service plesk-php81-fpm restart

Next we will install the Redis server:

apt-get install redis-server
systemctl start redis-server
systemctl enable redis-server

After that we change the Redis configuration with

nano /etc/redis/redis.conf

and add at the end of the file

maxmemory 256mb
maxmemory-policy allkeys-lru
requirepass secretpassword
rename-command CONFIG secretconfig

we can replace “secretpasswort” with a password and “secretconfig” with the desired secret command to change the configuration via CLI. After that the Redis server can be restarted with

systemctl restart redis-server

Important note / Cache-Key-Salt

In wp-config.php you should or must enter a salt (especially for redis and memcached) for the cache. Otherwise it can happen that the cache leaks into other WordPress installations! Additionally, for Redis, another Redis database (1-16) can be addressed per page:

define( 'WP_CACHE_KEY_SALT', 'geiledomain_6542bsPkn76vF' );
define( 'WP_REDIS_DATABASE', 15);

Leave a Reply

Your email address will not be published. Required fields are marked *