How To Install PHP OPcache on Ubuntu 20.04 | 22.04 LTS

In this guide, we will show you how to install PHP OPcache Extension o Ubuntu systems

OPcache is a popular open-source PHP extension that helps speed up the performance of PHP scripts with caching the compiled versions in memory.

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.

Install PHP OPcache on Ubuntu-APT method

Follow the steps below to get started with PHP OPcache :

  • Update your Ubuntu system packages with running the below command:
sudo apt update -y && sudo apt upgrade -y
  • PHP OPcache package is not available on Ubuntu base repository. So You can install it via importing PPA repo as follows:
sudo add-apt-repository ppa:ondrej/php
  • Run the command below to reflect on PPA
sudo apt update -y
  • Then install PHP  as shown below:
sudo apt install php8.2 -y

  • Once installed, check the version of PHP currently installed on the system by running the following command:
php -v
  • Then install the PHP-OPcache as shown below:
sudo apt install php8.2-opcache
  • Configure PHP to use the OPcache extension by updating your php.ini file with the following recommended settings:
sudo vim  /etc/php/8.2/apache2/php.ini

Then modify the following lines with these values:

  • Restart your Apache for the changes to take effect
sudo systemctl restart apache2
  • Check the version of PHP again, It will show the OPcache extension in the output as follows:
php -v

How to Remove (Uninstall) PHP OPcache

  • Remove PHP OPcache APT Method
sudo apt autoremove php8.2 php8.2-opcache --purge -y


That’s it


unixcop Admin


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook