Articles

How to Disable the PHP Opcache

PHP 5.5, 5.6, 7.0, 7.1, and 7.2 have a built-in opcache that is enabled by default.

The entire purpose of PHP's opcache is to speed up your scripts and save CPU by storing compiled PHP scripts in memory.

If you'd rather have slower apps and increased CPU usage to save memory, you can disable the opcache.

To disable PHP's opcache, you can SSH in as root and edit the following files:

/etc/php5.5-sp/conf.d/opcache.ini
/etc/php5.6-sp/conf.d/opcache.ini
/etc/php7.0-sp/conf.d/opcache.ini
/etc/php7.1-sp/conf.d/opcache.ini
/etc/php7.2-sp/conf.d/opcache.ini

Add the following line to the end of each of these files:

opcache.enable=0

Finally, restart each PHP version by running the following command as root:

sudo service php5.5-fpm-sp restart
sudo service php5.6-fpm-sp restart
sudo service php7.0-fpm-sp restart
sudo service php7.1-fpm-sp restart
sudo service php7.2-fpm-sp restart

Last updated: April 25, 2017