parent root
PHP: Installation - Manual

Installation

The process of installing OPcache varies depending on which version of PHP you're running. Please refer to the appropriate section below.

Note:

If you want to use OPcache with » Xdebug, you must load OPcache before Xdebug.

PHP 5.5.0 and later

OPcache can only be compiled as a shared extension. If you have disabled the building of default extensions with --disable-all , you must compile PHP with the --enable-opcache option for OPcache to be available.

Once compiled, you can use the zend_extension configuration directive to load the OPcache extension into PHP. This can be done with zend_extension=/full/path/to/opcache.so on non-Windows platforms, and zend_extension=C:\path\to\php_opcache.dll on Windows.

PHP 5.2, 5.3 and 5.4

This » PECL extension is not bundled with PHP.

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: » https://pecl.php.net/package/ZendOpcache.

A DLL for this PECL extension is currently unavailable. See also the building on Windows section.

Recommended php.ini settings

The following settings are generally recommended as providing good performance:

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

You may also want to consider disabling opcache.save_comments and enabling opcache.enable_file_override, however note that you will have to test your code before using these in production as they are known to break some frameworks and applications, particularly in cases where documentation comment annotations are used.

A full list of configuration directives supported by OPcache is also available.

add a noteadd a note

User Contributed Notes 6 notes

up
24
NoiseEee
5 years ago
While the "suggested" opcache settings for php.ini might be appropriate for a production server, you're going to want to change several while you're developing, or you're not going to see any changes to your code. Get familiar with what they mean before blindly pasting that into php.ini and assuming things are going to work well.
up
-9
dosercz
5 years ago
For me works (on windows) only filename without path (default extensions dir path is used)
zend_extension=php_opcache.dll
up
-14
Alex Stanciu
4 years ago
In case anyone has segfaults when using Xdebug with OpCache (even after updates, Xdebug after OpCache or other desperate strategies).
1. Disable OpCache from beeing loaded
2. Install/Enable APCu
Should be ok for a development box. On the production box you should use OpCache without Xdebug (as Xdebug slows down PHP ~3x - on our apps at least).
up
-11
rwilson0429 at yahoo dot com
2 years ago
Yes, as ohcc at 163 dot com explained, putting the zend_extension directive  in the [php] section of php.ini worked for me.

[php]
engine = On
zend_extension=php_opcache.dll
up
-20
matthias at himalayasystems dot be
5 years ago
I had a problem with installing on php 5.4 through pecl

I used
pecl install ZendOpache-beta
To force the install of the beta version

When restarting, php could not find opcache.so
Use the absolute path when assigning zend_extension.
So change zend_extension=opache.so
to
zend_extension=/usr/lib64/php/modules/opcache.so
up
-41
ohcc at 163 dot com
3 years ago
The zend_extension directive should be placed in the [php] section of php.ini otherwise it won't work.

Right configuration example

[php]
engine = On
zend_extension=php_opcache.dll

WRONG configuration example

[opcache]
zend_extension=php_opcache.dll
To Top
parent root