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

Back to top button