How to Install OPcache on Debian

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

In this guide, we will walk you through the installation of the Zend OPcache in Debian-based Linux distributions such as Ubuntu and Mint.

OpCache is an advanced caching module that operates similarly to other caching solutions. By keeping your site’s pre-compiled PHP pages in shared memory, it substantially improves PHP performance and, by extension, your website. This avoids the need for PHP to load these pages every time the server receives a request.

In this guide, we will We’ll be using Ubuntu 20.04 in this post, and we’ll show you how to install and enable the module on both Apache and Nginx web servers. If you need help setting a server, please refer to one of our other guides.

Install and Configure PHP OPcache for Apache Debian

To start, launch your terminal and update your package index:

$ sudo apt update

Then, as shown below, install the Apache web server, PHP, and PHP modules, including the php-opcache module.

$ sudo apt install apache2 libapache2-mod-php php-curl php-mbstring php-opcache php-mysql php-xml php-gd

The command installs the newest version of the Apache web server, as well as PHP and its extensions. Run the following command to see what version of PHP you have installed:

$ php –version

The OPcache caching module must now be enabled. To do this, make changes to the php.ini settings file.

$ sudo vim /etc/php.ini

Locate and uncomment the following lines

pcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=200

Save the changes and exit.

Then restart Apache to apply the changes.

$ sudo systemctl restart apache2

Finally, verify that Opcache has been enabled as follows:

$ php -i | grep opcache

The following output will be displayed on your screen.

Expected output

This is proof enough that the Opcache module has been successfully installed.

Install and Configure PHP OPcache for Nginx

Follow the procedures below if you want to use Nginx as your webserver of choice.

Install Nginx, PHP, and associated PHP extensions as before.

$ sudo apt install nginx php php-fpm php-cli php-curl php-mbstring php-opcache php-mysql php-xml php-gd

Once again, confirm the PHP version installed.

$ php -v

Next, access the php.ini configuration file to enable Opcache.

$ sudo vim /etc/php.ini

As before, uncomment the following lines to enable Opcache for Nginx.

opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=200

Save the changes and exit.

Then restart the Nginx web server and PHP-FPM service.

$ sudo systemctl restart nginx

Finally, confirm that Opcache was successfully installed:

$ php -i | grep opcache
Expected output

You should see that the Zend Opcache caching module was successfully installed.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook