Skip to content

Instantly share code, notes, and snippets.

@danielnunez
Forked from WillSquire/opcache_install.md
Created April 1, 2024 23:53
Show Gist options
  • Save danielnunez/8682d4bafd7f7c19d77d8c3c34b74f6f to your computer and use it in GitHub Desktop.
Save danielnunez/8682d4bafd7f7c19d77d8c3c34b74f6f to your computer and use it in GitHub Desktop.
OpCache install & configuration

OpCache

Installation

Install OpCache on FreeBSD with (note 56 resembles the current PHP version 5.6):

cd /usr/ports/www/php56-opcache && sudo make config-recursive install distclean

Configuration

Open up php.ini to configure OpCache settings:

sudo ee /usr/local/etc/php.ini

Find and uncomment the following directives (by removing the ; at the front of the directive's line), then set their values to the required value:

opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.use_cwd=1
opcache.revalidate_freq=60
opcache.fast_shutdown=1

The following can also be set, but in applications that use code comments as executable code (i.e. symfony's annotation) this will cause problems as it will strip comment out of the pre-compiled byte code:

opcache.save_comments=0
opcache.load_comments=0

opcache.max_accelerated_files should be higher than the amount of PHP files that are going to be cached. Fine tune this by counting the number of .php files in your project directory with (note the path used here is the default Apache DocumentRoot path, change as needed):

find /usr/local/www/apache24/data -iname *.php|wc -l

Check the OpCache running configuration in the command line with:

php -r 'var_dump(opcache_get_configuration());'

Check the status of OpCache with:

php -r 'var_dump(opcache_get_status(false));'

Restart Apache:

sudo apachectl graceful

###References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment