Installing and configuring PHP Opcache on Ubuntu 20.04 For Apache and Nginx
The guide below describes how to install PHP Opcache on Ubuntu 20.04 For both Apache and Nginx.
Made in seconds.
For Apache systems
We start the terminal and install Opcache:
1 | apt-get install php-opcache -y |
Edit the php.ini file
1 | nano /etc/php/7.4/apache2/php.ini |
and add at the end:
1 2 3 4 | opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=3000 opcache.revalidate_freq=200 |
We restart the Apache server:
1 | systemctl restart apache2 |
In the case of Nginx the procedure is very similar:
Installation:
1 | apt-get install php-opcache php-fpm -y |
Edit the php.ini file
1 | nano /etc/php/7.4/fpm/php.ini |
We add at the end of the file:
1 2 3 4 | opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=3000 opcache.revalidate_freq=200 |
And we overload services
1 | systemctl restart nginx |
1 | systemctl restart php7.4-fpm |