Install and Configure PHP OPcache on Ubuntu 20.04 | 18.04

This brief tutorial shows students and new users how to install and configure PHP OPcache on Ubuntu 20.04 | 18.04.

OPcache is an Apache module for the PHP interpreter that can be used to increase performance by storing precompiled scripts in shared memory space.

Using OPcache, PHP doe not need to load and interpret the same script everytime there’s a request. This can speed up performance for PHP based applications.

For those using WordPress and other PHP applications, then may be helpful in speeding up WordPress and others CMS platforms.

Configure PHP | PHP-FPM

If you’re running Apache, then PHP will be used. For Nginx, PHP-FPM is used instead.

Open the PHP configuration file with the following command.

If PHP is interpreted using the Apache module:

sudo nano /etc/php/7.4/apache2/php.ini

If PHP is interpreted using Nginx module:

sudo nano /etc/php/7.4/fpm/php.ini

To enable the use of OPcache, all you need to do is enable the related item, by changing the following line:

; Determines if Zend OPCache is enabled

with this:

; Determines if Zend OPCache is enabled

remove the ; initial if present.

Save the file and you’re done.

Restart PHP


sudo systemctl restart apache2

Nginx | PHP-FPM

sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx

Improvement Settings

The steps above enable OPcache. However, the default settings might not provide much improvements.

Use the line settings below to improve performance.

Increase memory consumption.


Number of scripts stored


Update frequency

opcache_revalidate_freq = 200

Save the file and exit. Then restart PHP again.

That’s it!


This post showed you how to configure OPcache to improve performance for PHP based applications. If you find any error above, please report below:

You may also like the post below:

1 Comment

  1. how i do i know opcache packed installed to my VPS ? ubuntu 20?


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.