10

I am trying to enable Opcache, but for some reason, after editing my php.ini file and restarting apache (even rebooting the server), it still does not get enabled. Running a test I can see that that the php files location:

Loaded Configuration File   /etc/php5/apache2/php.ini

Within that file I have added:

zend_extension=/usr/lib/php5/20121212/opcache.so
opcache.enable=1
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

The location of the zend extension was defined by locate opcache.so. This did not work. I then noticed that php was loading an additional file /etc/php5/apache2/conf.d/05-opcache.ini. In that file it looks like:

; configuration for php ZendOpcache module
; priority=05
zend_extension=opcache.so
opcache.enable=1
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

However, after restarting apache it still will not enable. The following is in my phpinfo() output:

Opcode Caching  Disabled

How can I get it to enable?

user2694306
  • 3,832
  • 10
  • 47
  • 95

6 Answers6

3

In the output from phpinfo(), have a look at the .ini files listed under:

Additional .ini files parsed

There may be something like

/usr/local/php5/php.d/20-extension-opcache.ini

Make sure opcache.enable=1 is set in this file.

crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • 1
    Thank you sir. This was driving me crazy and just like that it worked, followed by running sudo apachectl restart – kronus Apr 21 '20 at 00:04
2

You might be looking for the ini file location

cat /etc/php.d/10-opcache.ini
Ricardo Saracino
  • 1,345
  • 2
  • 16
  • 37
2

If everything else fails, you could try:

sudo yum install php-opcache

Solved the issue on my PHP 7.2 version for Fedora.

Turns out I didn't have opcache installed (a key giveaway was the lack of a .ini file on the "Additional .ini files parsed" section of phpinfo()).

Andrés
  • 21
  • 2
0

check the [opcache] section in php.ini

[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=0
Bartłomiej Wach
  • 1,968
  • 1
  • 11
  • 17
0

Common Misunderstanding

Theres settings for PHP Cli and PHP-FPM

What you are seeing is that Opcache is disabled for CLI

Create a php file in your server (should be accessible from web). i named it phpi.php, add the following:

<?php
phpinfo();
?>

Open it from a browser http(s)://your_ip_or_domain/path/to/phpi.php

Scroll down and look for Zend OPcache

if you see Opcode Caching up and running, then its enabled

enter image description here

janithcooray
  • 188
  • 2
  • 15
-1

First do this

sudo apt-get install libpcre3-dev

then

sudo pecl install zendopcache-beta
Sentry
  • 4,102
  • 2
  • 30
  • 38