Here is a step-by-step tutorial in English on how to enable OPcache. ----- ### Step 1: Install the OPcache PHP Extension First, you need to install the OPcache module for your specific PHP version. The package name is typically `php-opcache`, but it's a virtual package. You must specify the exact version. 1. **Check your PHP version:** `php -v` 2. **Install the correct package:** Replace `` with your PHP version (e.g., `8.3`, `8.4`). `sudo apt install php-opcache` This command installs the extension for both the CLI (Command-Line Interface) and PHP-FPM/Apache. ----- ### Step 2: Configure `php.ini` Now, you need to enable and configure OPcache in your PHP configuration file. The file's location depends on your web server. 1. **Find your `php.ini` file:** * **For Nginx/PHP-FPM:** `/etc/php//fpm/php.ini` * **For Apache:** `/etc/php//apache2/php.ini` 2. **Edit the file:** Open the file using a text editor like `nano`. `sudo nano /etc/php//fpm/php.ini` 3. **Add/Edit the `[opcache]` section:** Add or find the `[opcache]` section and ensure the following lines are present and uncommented (remove the `;` if it's there). ```ini [opcache] opcache.enable=1 opcache.memory_consumption=512 opcache.max_accelerated_files=20000 opcache.revalidate_freq=60 ``` * `opcache.enable=1`: This enables OPcache for your web server. * `opcache.memory_consumption`: Adjust this value based on your server's RAM and website size. For a 24 GB server and a large site, `512` is a good starting point. * `opcache.max_accelerated_files`: Adjust this based on the number of PHP files in your project. A value of `20000` or higher is recommended for large websites. * `opcache.revalidate_freq`: This tells OPcache how often (in seconds) to check for file updates. `60` is a good value for a production environment. ----- ### Step 3: Restart Your Web Server After saving the `php.ini` file, you must restart your web server for the changes to take effect. The command depends on your setup. * **For Nginx (with PHP-FPM):** `sudo systemctl restart php-fpm` * **For Apache (with mod\_php):** `sudo systemctl restart apache2` ----- ### Step 4: Verify that OPcache is Active To confirm that OPcache is working, create a PHP info file in your web root. 1. **Create a file named `info.php`:** ```php ``` 2. **View the file in your browser:** Navigate to `http://your_domain.com/info.php`. 3. **Check the OPcache section:** Search for **"Zend OPcache"**. The "Opcode Caching" status should be **"Up and Running"**. You will also see the configuration settings you just applied.