Enable Zend OPcache for PHP 5.5 or Install ZendOpcache for PHP 5.3 or PHP 5.4

Zend Opcache is part of PHP 5.5, however, it's not enabled by default. It's a successor to APC cache--meaning APC cache is never going to be compatible with PHP 5.5 or higher

Opcache is also around 10% faster than APC, and more stable.

However, if you're on PHP 5.3 or PHP 5.4, you can still use ZendOpCache, and it should still be a bit faster than APC

Enable OpCache (part of with PHP 5.5)

vi /usr/local/lib/php.ini

Paste this under your extension_dir

zend_extension=/FULL-PATH-FROM-ABOVE/opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

You can also try the below; which I haven't fully tested yet, however, one of our sites Magento would just display a 'white screen of death' when OPcache was enabled--I haven't fully tested the cause, but it definitely has to do with PHP 5.5.8 and OpCache 7.0.2 or 7.0.3-dev

zend_extension=/FULL-PATH-FROM-ABOVE/opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.max_wasted_percentage=5
opcache.use_cwd=1
opcache.validate_timestamps=0
opcache.revalidate_freq=60
opcache.fast_shutdown=1

Restart Apache and see if it installed correctly

service httpd restart
php -v

You should see something like:

PHP 5.5.8 (cli) (built: Jan 12 2014 20:27:27) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
 

Install Zend OpCache (for PHP 5.3 or 5.4 only)

This url will download the latest version: http://pecl.php.net/get/ZendOpcache

cd /usr/local/src
wget http://pecl.php.net/get/ZendOpcache
# to get the latest (master) build do the following instead:
# wget https://github.com/zendtech/ZendOptimizerPlus/archive/master.zip
tar xvfz zendopcache-7.x.x.tgz
cd zendopcache-7.x.x
phpize
whereis php-config 
# set the path below
./configure --with-php-config=/usr/local/bin/php-config
make
make install
# note the install path because you will use it below
vi /usr/local/lib/php.ini

Paste this under your extension_dir

zend_extension=/FULL-PATH-FROM-ABOVE/opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

... Or this, which I haven't fully tested--see note above.

zend_extension=/FULL PATH FROM ABOVE/opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.max_wasted_percentage=5
opcache.use_cwd=1
opcache.validate_timestamps=0
opcache.revalidate_freq=60
opcache.fast_shutdown=1

Restart Apache and see if it installed correctly

service httpd restart
php -v

You should see something like:

PHP 5.5.8 (cli) (built: Jan 12 2014 20:27:27) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

Troubleshooting

After updating to PHP 5.5.8 I started getting zend_mm_heap corrupted and segment fault errors--especially while using drush.   

To fix this, simply follow the above instructions for PHP 5.4 to install the latest master version (which at the time of this writing is Zend OPcache v7.0.4-dev)

Afterwards you should see something like this:

PHP 5.5.8 (cli) (built: Jan 21 2014 22:19:07) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

UPDATE 2014-01-21

The above still doesn't fix the PHP 5.5.8 error... The solution is to extract the opcache that comes with PHP 5.5.6 and build that:

cd /usr/local/src
wget http://us1.php.net/get/php-5.5.6.tar.gz/from/this/mirror
tar xvfz php-5.5.6.tar.gz
mv php-5.5.6/ext/opcache/ ./
cd opcache/
phpize
whereis php-config
# set the output path below
./configure --with-php-config=/usr/local/bin/php-config
make
make install
service httpd restart
#if you have memcached
service memcached restart
php -v

# If you're feeling adventurous, you can try the above in a single line:
wget http://us1.php.net/get/php-5.5.6.tar.gz/from/this/mirror; tar xvfz php-5.5.6.tar.gz; mv php-5.5.6/ext/opcache/ ./; cd opcache/; phpize; ./configure --with-php-config=/usr/local/bin/php-config; make; make install; service httpd restart; service memcached restart; php -v

 

Should show Zend OPcache v7.0.3-dev -- yes v7.0.3-dev is correct and *is* different than the one that ships with PHP 5.5.7 and PHP 5.5.8

PHP 5.5.8 (cli) (built: Jan 12 2014 20:27:27) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

As noted above, some Magento sites would just display a 'white screen of death' when OPcache was enabled--I have tested install opcache from PHP 5.5.6 and it fixes the problem, but it definitely has to do with PHP 5.5.7 and PHP 5.5.8  ... IF you are still experiencing problems, the solutions is to disable OPcache in your php.ini via 'opcache.enable=0'

Tags: Linux cache APC opcache