How to Install and Configure PHP OPcache on Ubuntu 20.04January 18, 2022
In this tutorial, we will show you how to install and configure PHP OPcache on an Ubuntu 20.04
OPcache is an Apache module for the PHP interpreter. It is used to increase performance by storing precompiled scripts in shared memory space. Generally, it is used to speed up the performance of WordPress and PHP-based applications. OPcache removing the need for PHP to load and parse scripts on each request.
Install Apache and PHP
Update all available repositories on your system and install the Apache webserver using the apt command below.
sudo apt update && sudo apt upgrade -y
First, you will need to install Apache, PHP and other PHP extensions to your server, if you already have Apache and PHP installed on your server you can skip this step, just make sure you have the
php-opcache PHP extension. You can install them with the following command:
sudo apt-get install apache2 libapache2-mod-php php php-cli php-opcache php-mysql php-zip php-gd php-mbstring php-curl php-xml -y
Next, you will need to enable the PHP OPcache by editing php.ini file.
sudo nano /etc/php/7.4/apache2/php.ini
Uncomment the following lines from the php.ini file:
Save and close using the
CTRL + X combination, then press
Y and confirm by pressing
ENTER. After closing the file then restart Apache service to apply the changes: