How to enable OPcache in Debian?

Just installed php5-fpm. All sources say that apc module has been replaced with OPcache and it's compiled by default but not enabled.

How can I enable this module. I can not find opcache.so file on my server

I have checked /usr/lib/php5 and /etc/php5 but can not find it.

php -v
PHP 5.4.4-14+deb7u4 (cli) (built: Aug 23 2013 14:37:41)

You can update PHP like shaun m says, or if you don't want to do that you can install zendopcache from PECL

Check for latest version here, this installs version 7.0.3.

Install "pecl" via php-pear

`sudo apt-get install -y php-pear`

Install build dependencies

sudo apt-get install -y build-essential php5-dev

Install Zend OpCache

sudo pecl install zendopcache-7.0.3

Find the location of opcache.so

sudo find / -name 'opcache.so'

Mine is

/usr/lib/php5/20100525/opcache.so

Now create opcache.ini

sudo vim /etc/php5/mods-available/opcache.ini

Add this info

zend_extension=/usr/lib/php5/20100525/opcache.so # File path from above
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

Now create a symlink for the conf file

sudo ln -s /etc/php5/mods-available/opcache.ini /etc/php5/conf.d/20-opcache.ini

Restart services

sudo service php5-fpm restart
sudo service apache2 restart

Confirm install

php -v

It should give mention of

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

Then (optionally) finish by cleaning up

sudo apt-get remove --purge build-essential php5-dev

Reference


OPCache is only enabled and compiled in by default in the new PHP 5.5, not the 5.4 that comes with Wheezy. If you'd like to use OPCache and PHP 5.5 in Debian, you'll have to add the dotdeb repos (see below) and install from there.

deb http://packages.dotdeb.org wheezy-php55 all 
deb-src http://packages.dotdeb.org wheezy-php55 all