How to Install PHP OPCache APC/APCu Memcached and Redis on VestaCP CentOS
In this tutorial we’ll implement and install various type of opcache and object cache in order to increase the performance of your websites and lower the loads for server.
OPCache and object cache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.
In other words, a PHP script when it is executed, is compiled into opcode/object cache (memcache and redis), code that is understandable by the machine. OPCache and object cache stores this code into memory on the first execution, to be reused afterwards, thus leading to performance boosts.
Lets get Started :
First install Remi repo :
CentOS 8
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
CentOS 7
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm
CentOS 6
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6.rpm
To install Zend Opcache :
OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.
yum install php-opcache
After installation you need to restart Apache/php-fpm :
if you’re using Apache (mod_php) :
service httpd restart
If you’re using PHP-FPM :
service php-fpm restart
To install APC/APCu :
APC is a free, open, and robust framework for caching and optimizing PHP intermediate code.
yum install php-pecl-apcu
After installation you need to restart Apache/php-fpm :
if you’re using Apache (mod_php) :
service httpd restart
If you’re using PHP-FPM :
service php-fpm restart
To install Memcached :
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
For PHP 5.xx
yum -y --enablerepo=remi,remi install memcached
For PHP 7.xx
yum -y --enablerepo=remi,remi install memcached
Start memcached Service :
service memcached start
Start the memcached on boot :
Centos 6 :
chkconfig memcached on
Centos 7/8 :
systemctl enable memcached
After installation you need to restart Apache/php-fpm :
if you’re using Apache (mod_php) :
service httpd restart
If you’re using PHP-FPM :
service php-fpm restart
To install Redis :
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.
yum install redis php-pecl-redis
Start Redis Service :
service redis start
Start the Redis on boot :
Centos 6 :
chkconfig redis on
Centos 7/8 :
systemctl enable redis
After installation you need to restart Apache/php-fpm :
if you’re using Apache (mod_php) :
service httpd restart
If you’re using PHP-FPM :
service php-fpm restart
Also Check : How to Optimize Nginx and PHP-FPM VestaCP CentOS
Can I use two different object cache for a single wordpress site?
Memcached Redux for memcached.
Redis object cache for redis.
Is is possible to use both of them on the same wordpress site?
its not recommended to use redis and memcached together
you can use :
redis + zend opcache
or
memcached + zend opcache
Which according to you is better?
redis + zend opcache
or
memcached + zend opcache
If the WordPress installations have heavy themes & lots of plugins, and WP Super Cache
I am guessing I should use the 2nd option because in this tutorial: https://www.uxlinux.com/how-to-optimize-apache-php-and-mysql-performance-for-1gb-ram-vps/ a small VPS would work too.
memcached + zend opcache is better in my opinion mysterdata is using the same.
Hello!
Nice tutorial. Can you also provide instructions on how to use each of these in wordpress?
Hello Roy,
you can check redis implementation under Step 2:
https://www.uxlinux.com/speedup-wordpress-decrease-server-load-redis-cache-cwp-centos-webpanel/
For memcached implementation (php 7) check the “WordPress Configuration with Memcached ” part :
https://www.uxlinux.com/configure-and-speedup-wordpress-with-memcached-on-php-7/
Zend Opcache doesn’t required any configurations
APC/APCu : You can use w3total cache plugin