How to speed up php app by installing opcache on server

There are many ways to install opcache on a server.

The top two ways are using

  1. Install opcache Using PECL
  2. Install opcache using apt-get

Install opcache Using PECL

To install opcache using pecl run the command pecl install php-opcache

Install opcache using apt-get

The easiest way is to use the package manager for your operating system.

For example, on Debian or Ubuntu, you can use the following command to install opcache: sudo apt-get install php-opcache

On CentOS, you can use the following command to install opcache: sudo yum install php-opcache.

Once opcache is installed, you need to configure it. The best way to do this is to use the opcache.ini file.

This file is located in the /usr/local/etc/php/8.1/conf.d/ext-opcache.ini directory on Debian or Ubuntu, and in the /etc/php.d directory on CentOS.

The opcache.ini file contains the following settings:

; configuration for php OPcache extension 
; priority=10 
opcache.revalidate_freq=60 ; how often to check file timestamps for changes (in seconds) 
opcache.save_comments=1 ; save comments in PHP files 
opcache.load_comments=1 ; load comments from PHP files 
opcache.file_update_protection=2 ; how many seconds to wait between file updates.

The most important settings are the opcache.enable and opcache.memory_consumption settings.

The opcache.enable setting should be set to 1 to enable opcache, and the opcache.memory_consumption setting should be set to the amount of memory that you want to allocate to opcache. The default value is 128, but you may want to increase this value if you are running a busy website.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top