I'm using the standard Apache and PHP 7.1 (not Homebrew) that comes with Mac High Sierra. However, it appears that this version doesn't have Opcache enabled even though it should come as standard with PHP 7. It's even listed in phpinfo()
under "Module Authors", but no section showing it's actually installed. Calling opcache_get_status
gives a fatal error.
I've installed the extension via Homebrew, and linked the opcache.so
file. It appears to be working on the CLI but not in Apache. For some reason the CLI and web are using different ini files:
/usr/local/etc/php/7.1/php.ini
for CLI/etc/php.ini
for webThe CLI is parsing the addition files including /usr/local/etc/php/7.1/conf.d/ext-opcache.ini
, and php -i
shows Opcache. But phpinfo()
in the browser does not - no additional ini files are parsed.
I currently have this in /etc/php.ini
:
[opcache]
zend_extension="/usr/local/opt/php71-opcache/opcache.so"
opcache.enable=1
But still nothing. I followed the exact same process for xdebug and it worked fine. What am I missing?
I wonder if it would be easier to use the Homebrew version of PHP. But I don't appear to have the required .so
file. Various tutorials say to put this in Apache's httpd.conf
:
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
But the libexec
directory does not exist. There is lib
but neither this nor any other directory has any .so
file.
For me it worked by these steps:
extension_dir
in "phpinfo()" page, I got a path
/usr/lib/php/extensions/no-debug-non-zts-20160303
ls -lh /usr/lib/php/extensions/no-debug-non-zts-20160303
, I found "opcache.so" , I guess it's installed when upgraded to "High Sierra"[opcache] zend_extension = opcache.so opcache.enable = 1
EDIT / CONCLUSION
Since "opcache extension" is installed on Mac OS High Sierra by default, the solution of enabling opcahe on Mac OS High Sierra is:
sudo cp /etc/php.ini.default /etc/php.ini
zend_extension = opcache.so
to /etc/php.ini
and set "opcache" enable:php.ini opcache section looks like:
[opcache]
zend_extension = opcache.so
opcache.enable = 1