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

Configiration
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:
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
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. ?
Comment
Preview may take a few seconds to load.
Markdown Basics
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Italics *asterisks*
Bold **double asterisks**
Code
Inline Code
`backtick`Code Block```
Three back ticks and then enter your code blocks here.
```
Headers
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
Quotes
> type a greater than sign and start typing your quote.
Links
You can add links by adding text inside of [] and the link inside of (), like so:
Lists
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
Images
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the image URL inside of (), like so:
Dividers
To add a divider you can add three dashes or three asterisks:
--- or ***

Comments (0)