Enable PHP 5.5 Opcache on Ubuntu 14.04 with Nginx and PHP-FPM

May 15, 2014 42.2k views
Making the switch from APC to Opcache now that it's standard with Ubuntu 14.04. All the tutorials seemed to be on Apache so thought I'd share what I did. The first change and restarting php I believe is all you need to do while the other changes are for performance and will vary based on your needs. If others have recommendations or additional advice please pipe in! sudo vim /etc/php5/fpm/php.ini Change: ;opcache.enable=0 to opcache.enable=1 Change: ;opcache.memory_consumption=64 to opcache.memory_consumption=128 Change: ;opcache.max_accelerated_files=2000 to opcache.max_accelerated_files=4000 Change: ;opcache.revalidate_freq=2 to opcache.revalidate_freq=60 Then restart: sudo service php5-fpm restart
1 comment
  • This is an awful tutorial. You're not teaching anybody anything, you're just telling them to change some values with no idea what they are.

12 Answers
Thanks for the tip! Here's the full list of configuration options you can tweak:


Anyone else have any recommendations?
Hey Chris,

Trying to enable opcache on my end with the same setup as yours, php.ini has same configs, and have restarted both nginx and fpm, no dice.. Even added zend_extension=opcache.so within php.ini, and went ahead and added



within /etc/php5/mods-available/opcache.ini with no results.

Installed https://raw.github.com/rlerdorf/opcache-status/master/opcache.php and am getting nada.. wondering what you may have done differently to enable opcache?
  • Hi,

    I am not sure about Ocean Droplet configuration.

    I am using another VPS and I had to make sure the full path is correct for any of the *.so files.

    If you look closer, (in my example...), I do no thave a /etc/php5/conf.d folder. The conf.d folder is located in /etc/php5/fpm/conf.d because I have the php5-fpm package installed on my ubuntu 14.04.

    Now if you go to your /etc/php5/mods-available, you will see a few of the *.ini files.

    As an example, open the opcache.ini.

    Do you see extension=opcache.so?

    Now do a locate opcache.so in a terminal. Mine was located in /usr/lib/php5/20121212/opcache.so...

    As soon as I change the extension=opcache.so to extension=/usr/lib/php5/20121212/opcache.so and restarted php5-fpm service, all came to light!

    I checked all the ini files in mods-available and updated all the path for the extensions.

    I hope this can help somebody.

  • Did you the DO LEMP stack application? That's what i used.

Did you make sure to restart Nginx and php5-fpm after making the changes?

service php5-fpm restart
service nginx restart
Yep, take a look ( will take this down after problem is resolved ) http://www.waxdev.com/opcache.php
On Ubuntu 14.04, installing php5-fpm, uncommenting the php related block in my nginx configuration, and restarting nginx was enough to get this working for me. Maybe comparing my info.php with yours will shed some light:

This is a temporary server. So those links won't last. Here's the php info in plain text for posterity:

Heres my phpinfo, www.waxdev.com/info.php

As for uncommenting out the php related block within /etc/nginx/nginx.conf, I dont see a php block..
So turns out, my php5-fpm wasnt restarting properly, after checking error logs and proper restart, opcache is running smoothly! Thanks again

Thanks for the guide Chris! I have one question. I enabled opcache with php 5.6 and downloaded a web-viewer. It shows me the opcache is running and everything is fine, but when I type in console php -v it doesn't show the with Zend opcache v...etc. How can I be sure it works?

hi @asb ,
i have one question,
should that configuration suite small droplets like 512 as well?

and thx for the info by the way @chris324769

How do we verify if its working??

  • Create a file with the following contents:

    echo 'OPCache is ' . (is_array(opcache_get_status()) ? 'enabled' : 'disabled');

    and then browse to it. If OPCache is enabled, it should say "OPCache is enabled".

I have opcache up and running but there is no files cached. There is a lot of misses and blacklist misses but no cached keys and no cached scripts. What could be wrong?

Have another answer? Share your knowledge.