How to Install PHP OPCache APC/APCu Memcached and Redis on VestaCP CentOS

by Sandeep B.

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 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 install memcached memcached-devel php-pecl-memcache

For PHP 7.xx

yum install memcached memcached-devel php-pecl-memcached

Start memcached Service :

service memcached start

Start the memcached on boot :
Centos 6 :

chkconfig memcached on

Centos 7 :

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 :

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

If this post helps you in any way please consider a donation

Donate with PayPal :

md-donate

Donate with Paytm :

md-donate

You may also like

6 comments

Roy Gomez April 10, 2018 - 6:06 pm

Hello!
Nice tutorial. Can you also provide instructions on how to use each of these in wordpress?

Reply
Sandy April 10, 2018 - 7:52 pm

Hello Roy,
you can check redis implementation under Step 2:
https://www.mysterydata.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.mysterydata.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

Reply
Roy Gomez April 10, 2018 - 9:37 pm

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?

Reply
Sandy April 10, 2018 - 9:38 pm

its not recommended to use redis and memcached together
you can use :
redis + zend opcache
or
memcached + zend opcache

Reply
Hitesh L. May 9, 2019 - 10:06 am

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.mysterydata.com/how-to-optimize-apache-php-and-mysql-performance-for-1gb-ram-vps/ a small VPS would work too.

Reply
Sandy May 10, 2019 - 4:43 pm

memcached + zend opcache is better in my opinion mysterdata is using the same.

Reply

Leave a Comment