I am finding it tricky to enable OPcache on my MacOS Sierra (10.12.6) system.
php --ini shows the ini file used:
Configuration File (php.ini) Path: /usr/local/etc/php/7.0
Loaded Configuration File: /usr/local/etc/php/7.0/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.0/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.0/conf.d/ext-pdo_pgsql.ini
My php.ini looks like this:
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
However, when I look at phpinfo() it shows the following:
I've restarted Apache after making the change to my php.ini to include opcache, but it doesn't appear to be recognised.
I installed PHP with Homebrew, not MAMP although I do have MAMP install but unused.
I got to the bottom of this eventually...
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.
Related
My current config:
- MacOS Mojave
- PHP 7.3.5 installed via Homebrew
- XDebug 2.7.2 installed via PECL
- get_loaded_extensions() in both CLI and built-in server is enabled
While trying to configure XDebug on Mac I came across a strange problem.
When calling
$ php --ini
I get
Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File: /usr/local/etc/php/7.3/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.3/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.3/conf.d/ext-xdebug.ini
whereas calling
print php_ini_scanned_files();
in the script executed via built-in PHP server yields
/usr/local/etc/php/7.3/conf.d/ext-opcache.ini
Web server does not include my xdebug config, therefore there is no way to set xdebug.remote_enable=1 option properly.
What is even "better" is that editing /usr/local/etc/php/7.3/php.ini to cause parsing errors gives no warnings whatsoever.
I'm puzzled. Does anyone has any idea what's the reason behind this?
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 web
The 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:
Search extension_dir in "phpinfo()" page, I got a path
/usr/lib/php/extensions/no-debug-non-zts-20160303
By execute 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"
Create "/etc/php.ini" (by copy "/etc/php.ini.default"), and modify:
[opcache]
zend_extension = opcache.so
opcache.enable = 1
Restart apache, module "opcache" is enabled
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:
Create "/etc/php.ini" if you don't have one, by simply copy the default configuration: sudo cp /etc/php.ini.default /etc/php.ini
Add 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
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?
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.
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()).
You might be looking for the ini file location
cat /etc/php.d/10-opcache.ini
check the [opcache] section in php.ini
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=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
First do this
sudo apt-get install libpcre3-dev
then
sudo pecl install zendopcache-beta
I am using MAMP Pro 3.0.5 to run Apache/PHP on my computer, running OS X (Yosemite DP2). I just installed an old project on my server, but I get an conflict with the intl package that is now being initialized (I guess this was not on my previous setup).
The phpinfo() provides me with the fact, that intl is laoded through the configuration command, which ends:
'--with-mcrypt=shared,/Applications/MAMP/Library' '--with-openssl' '--enable-zip' '--with-iconv=/Applications/MAMP/Library' '--enable-opcache' '--enable-cgi'
'--enable-intl'
'--with-icu-dir=/Applications/MAMP/Library' '--with-tidy=shared'
I cannot figure out where to edit this, so I can remove --enable-intl?
Update 1
There is not reference to intl in php.ini:
Update 2
$ /Applications/MAMP/bin/php/php5.5.10/bin/php --ini
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.5.10/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php5.5.10/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Apache and my terminal are using two different php versions. The one that I installed via macports and the other is the one that comes with the mac.
My phpconfig tells me is using the mac one:
Configuration File (php.ini) Path /etc
Loaded Configuration File /etc/php.ini
And the Terminal version is using the one installed via macports:
php --ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File: (none)
Scan for additional .ini files in: /opt/local/var/db/php5
Additional .ini files parsed: /opt/local/var/db/php5/intl.ini
How can I say to apache to load the macports version of php, and how can I change the "Loaded Configuration File" which is actually none?
UPDATE:
I solved how to Load the Conf file:
Copy the mac php.ini into /opt/local/etc/php5 (the "Configuration File (php.ini) Path") :
sudo cp /etc/php.ini /opt/local/etc/php5/
and how to change the php.ini that Apache is reading:
sudo nano /etc/apache2/httpd.conf
Just after the LoadModule php5_module add the line:
PHPINIDir "/opt/local/etc/php5/php.ini"
But I still have two different php running. So the question is how to say to apache to load my macports php?
UPDATE 2:
I've been reading for a solution and this is changing the path of the LoadModule php5 in the http.conf:
LoadModule php5_module /opt/local/apache2/modules/mod_php54.so
But actually I have no mod_php54.so in that folder.
The MacPorts documentation has a good step-by-step for setting up a MAMP install. I found it really useful when I went through the process.
https://trac.macports.org/wiki/howto/MAMP
Jump down to step four and look at the 'Register PHP with Apache' section. There are also quite a few other steps that you might need to study. It looks like you've gotten some of them already.