How to Install OPCache to Improve PHP Performance On CentOS / RHEL 7,8

OPcache is a type of OPcode caching. It is a powerful PHP extension built to enhance PHP performance. It works by storing pre-compiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

Have a look at the diagram to see how OPCache executes code:


Table of Contents

  1. Install OPCache
  2. Verify Installation
  3. Configiration

Install OPCache

I hope PHP is installed on your server. If the server doesn’t contain PHP, please follow this article to install PHP on your server.

To install PHP OPCache, run this command:

# centos 8
sudo dnf install php-opcache -y

# centos 7
sudo yum install php-opcache -y

Verify Installation

To verify installation run this command:

php -v

You’ll see the output like:

You can also verify from PHP info:


After completing the installation, we can easily configure OPCache. Open OPCache config file:

nano /etc/php.d/10-opcache.ini

Now we can set our own config like:


You can see all available config options from here.

Lastly, restart the webserver for Opcache to start working.

# nginx
sudo systemctl restart nginx

# apache
sudo systemctl restart httpd

That’s all. Thanks for reading.

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.