The Zend OPcache is a caching system that seeks to improve PHP performance by keeping precompiled PHP code in the shared memory of your web server. Since PHP is an interpreted language that has to be compiled into a set of intermediate instructions (“opcodes”) when someone accesses your PHP page or site, not having to perform this recompilation for every request can reduce both the response time and load on your server.
OPcache is only an opcode cache, as compared with APC, which is an opcode cache and data store; that is, APC can cache your site-specific data like variables and database material for faster retrieval. If you run OPcache, you may also want to run a separate data store or “user” cache, like APCu.
Zend OPCache Installation
If you’re running PHP 5.5 or later, Zend OPcache is probably already installed. To check, run php -v:
$ php -v PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
In Ubuntu 14.04 Server, the Zend OPcache installs automatically when you run apt-get install php5. Since Ubuntu 12.04 Server defaults to PHP 5.3.10, assuming you haven’t installed a later PHP version, you’d need to install OPcache separately:
$ apt-get install php-pear build-essential $ pecl install zendopcache # latest release
Create an opcache.ini file under /etc/php5 containing the path to the opcache.so file installed by PECL:
$ opcode_path=`find / -name 'opcache.so'`; echo "zend_extension="$opcode_path > /etc/php5/conf.d/opcache.ini;
Then add some additional configuration directives to opcache.ini, and restart your web server:
opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 opcache.enable=1 opcache.save_comments=0
$ service apache2 restart $ service php5-fpm restart
And verify that OPcache is installed:
$ php -v PHP 5.3.10-1ubuntu3.21 with Suhosin-Patch (cli) (built: Oct 28 2015 01:43:56) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Zend OPcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies