Since PHP 5.5 Opcache is baked right in, however its disabled by default. If you’re working on a shared host, then its pretty unlikely you’ll be able to get this working, however if you, like me, just switched over to Digitalocean and are loving the new freedom you have to set up the server, you’ll want to follow these quick tips.
First you need to ssh into your server, i’ll leave that up to you to figure out. Once inside you need to know where the file “opcache.so” file is situated. This file needs to be added to your ‘php.ini’ file and so to find it, we run the following command:
find / -name "opcache.so"
This searches your box for the file and gives you back a location:
Now we have that location we need to add a few lines to the php.ini file. There could be a couple on your system, or to just make the process of finding it quicker lets use the following command to see where exactly it is:
//on *nix machines php -i | grep 'Configuration File' //on windows php -i | find /i "Configuration File"
This will produce something that looks like
Loaded Configuration File => /etc/php5/cli/php.ini
You can now edit that file and place the following at the bottom
zend_extension=<The location to your opcache.so file from above>/opcache.so opcache.enable_cli=1 opcache.enable=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1
You may have to restart Apache or PHP-FPM before the settings take affect, but that will depend on your setup.
To check that its working, have a look in the phpinfo and search for ‘opcache’. There should be a section dedicated to ‘Zend Opcache’ and look something like this: