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
- Verify Installation
- 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:
Verify Installation
To verify installation run this command:
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:
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.
That’s all. Thanks for reading. ?