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
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
To verify installation run this command:
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:
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.
That’s all. Thanks for reading. ?
# nginx sudo systemctl restart nginx # apache sudo systemctl restart httpd
Preview may take a few seconds to load.
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Bold **double asterisks**
Three back ticks and then enter your code blocks here.
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
> type a greater than sign and start typing your quote.
You can add links by adding text inside of  and the link inside of (), like so:
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
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:
To add a divider you can add three dashes or three asterisks:
--- or ***