How To Install PHP OPcache on Ubuntu 20.04 | 22.04 LTS

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 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:

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
  • 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

Conclusion

That’s it

Thanks.

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook