Hi, as written on subject, how can i configure opcache on php 7 and what should be the optimized configuration for 10$ droplet?
thanks in advance.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Normally I use something like:
opcache.revalidate_freq=0
opcache.validate_timestamps=0 (comment this out in your dev environment)
opcache.max_accelerated_files=7963
opcache.memory_consumption=192
opcache.interned_strings_buffer=16
opcache.fast_shutdown=1
Which is from:
https://www.scalingphpbook.com/blog/2014/02/14/best-zend-opcache-settings.html
Depending on file count, you may need to increase opcache.max_accelerated_files. That said, the above is allocating up to 192MB, which may be excessive depending on your application. If you find that to be high (i.e. you’re only using 25% of that at any give time), you can reduce that down further.
Heya,
Updating the question for PHP 7 and PHP8 in case anyone stumbles upon it:
The opcache extension is bundled with PHP 5.5.0 and later versions. It improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request. Here’s a sample configuration to use as a starting point for tuning opcache on a server with limited resources, like a $10 droplet:
Open your opcache.ini file, which you can typically find at /etc/php/7.4/cli/conf.d/10-opcache.ini or /etc/php/8.0/cli/conf.d/10-opcache.ini depending on the version of PHP you’re using. You might need to adjust these paths based on your PHP installation.
Here’s a basic configuration to start with:
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
; Generally you should probably leave this off, because CLI PHP scripts are usually one-off tasks
opcache.enable_cli=0
; The OPcache shared memory storage size.
; For a $10 droplet, you can start with a size of 128 megabytes and adjust as necessary
opcache.memory_consumption=128
; The maximum number of keys (scripts) in the OPcache hash table.
; Only necessary to increase on very large sites
opcache.max_accelerated_files=5000
; The maximum percentage of "wasted" memory until a restart is scheduled.
opcache.max_wasted_percentage=5
; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thereby eliminating possible collisions between
; files with the same base name.
opcache.use_cwd=1
; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
opcache.validate_timestamps=1
; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation.
; ("1" means validate once per second, but only once per request.
; "0" means always validate)
opcache.revalidate_freq=60
; Enables or disables file search in include_path optimization
opcache.revalidate_path=0
; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
opcache.save_comments=1
Remember to restart your PHP-FPM or Apache service to apply these changes:
sudo systemctl restart php7.4-fpm or sudo systemctl restart php8.0-fpmsudo systemctl restart apache2Please adjust these configurations according to your application needs. The optimal settings can vary depending on the characteristics of your site and the amount of memory on your server. It’s also recommended to monitor your server’s performance and memory usage to tune these settings further.
Lastly, don’t forget to keep your PHP version and extensions, including opcache, up to date to benefit from the latest improvements and bug fixes.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.