10

I'm setting up a local server to test configurations; it's a clean 14.04 LAMP server, as selected during OS install.

If I understand correctly, OPCache comes with PHP 5.5 (php -v confirms this) but in a disabled state. I've followed the Internet's suggestions to enable it, however I'm receiving mixed messages about whether or not this has been successful.

My php.ini has

zend_extension=/usr/lib/php5/20121212/opcache.so
opcache.enable=1
opcache.enable_cli=1

yet php -i, after restarting the machine, is telling me

Opcode Caching => Disabled
Optimization => Disabled
Startup Failed => Opcode Caching is disabled for CLI

opcache.enable => On => On
opcache.enable_cli => Off => Off

i.e. it's apparently enabled, and simultaneously disabled.

Is enabling OPCache possible with the 14.04 repository PHP package, or do I need to compile PHP from source?

8

For some reason, setting fast_shutdown=1 was causing problems and preventing OPCache from starting. Once this was set to 0, OPCache is successfully up and running (possibly related to this bug?).

All that is needed therefore to enable OPCache is to set

; Determines if Zend OPCache is enabled
opcache.enable=1

in Apache's php.ini followed by a server restart

service apache2 restart

Side note: php -i tends to use a different php.ini from Apache (e.g. /etc/php5/cli/php.ini), hence the confusing discrepancy in the original question.

  • This didn't fix my issue. Any more ideas? I am using php5-fpm and am editing the correct php.ini (fast shutdown changed from 1 to 0 in PHPInfo) and i did restart php5-fpm as well as nginx – Maciej Swic Mar 4 '15 at 9:52
  • For me still same problem :/ logs: [Sat Jun 13 19:54:33.435550 2015] [core:notice] [pid 19088] AH00060: seg fault $ PHP Warning: Module 'Zend OPcache' already loaded in Unknown on line 0 PHP Warning: Zend OPcache: module registration failed! in Unknown on line 0 – Codium Jun 13 '15 at 17:53
  • I've figured it out. I've install opcache via sudo php5enmod opcache – Codium Jun 13 '15 at 17:57
  • So if /etc/php5/cli/php.ini is incorrect, what is the correct path? – Qian Chen Jul 8 '15 at 18:42
2

I faced this exact same problem through the day and am glad I solved it in the below manner. Although, the above reply is marked as an answer, it is clear from the comments to that answer that it doesn't completely answer the question.

The correct file to enable is in

/etc/php5/cli/conf.d 

Then enter the following in there

zend_extension=opcache.so
opcache.memory_consumption=128
opcache.max_accelerated_files=2500
opcache.interned_strings_buffer=8
opcache.revalidate_freq=60
opcache.fast_shutdown=1

Dont forget to restart apache

Use a tool like Opcache status to check if everything is fine and it will help you with areas to fine tune.

Hope that helps someone.

1

I ran into this when using php-fpm. I discovered in /etc/php5/fpm/conf.d that there was a symlink 05-opcache.ini to ../../mods-available/opcache.ini and one 20-opcache.ini pointing to the same place. That was causing a conflict.

I removed one (the 20 since that had a later modification date), restarted php-fpm, and everything came back.

0

correct file is :/etc/php5/apache2/conf.d/user.ini

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.