Want to subscribe to topics you're interested in?
Become a Member

Wordpress Planning to add Wordpress OpCache Plugin to centmin.sh menu option 22 installs

Discussion in 'Blogs & CMS usage' started by eva2000, Apr 16, 2020.

  1. eva2000

    eva2000 Administrator Staff Member

    45,183
    10,276
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,926
    Local Time:
    8:23 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Centmin Mod 123.09beta01 and newer have a wordpress auto installer and nginx site auto install configuration routine via centmin.sh menu option 22 which also preinstalls some performance and security related Wordpress plugins. You can see an example of such installation at https://servermanager.guide/122/how-to-install-wordpress-on-centmin-mod-lemp-stack-guide/. I plan to update centmin.sh menu option 22 routine to add Wordpress OpCache plugin which will allow you to see Zend Opcache statistics as well configure it to purge Zend Opcache cache on Wordpress updates. So this thread is a discussion for Centmin Mod Wordpress users to see if Wordpress OpCache plugin is something they'd like to see added and for folks to manually test install on their Wordpress sites and see if it works for them.

    Centmin Mod Wordpress & PHP Zend Opcache Background



    By default Centmin Mod PHP-FPM installs with Zend Opcache bytecode caching for better performance but instead of the default opcache.revalidate_freq setting of 2 seconds, Centmin Mod defaults to 180 seconds for better performance due to less rechecking for PHP modifications, updates or changes.
    The longer the interval set, the better the performance. But this means PHP script modifications and edits do not register and take effect for the duration of that interval or only until you restart PHP-FPM service to flush the cache. Usually, after I update PHP code, I do a PHP-FPM restart which is just habit :)

    SSH command to view Zend Opcache settings which have their custom defaults set in /etc/centminmod/php.d/zendopcache.ini
    Code (Text):
    php --ri 'Zend Opcache'
    
    Zend OPcache
    Opcode Caching => Disabled
    Optimization => Disabled
    SHM Cache => Enabled
    File Cache => Disabled
    Startup Failed => Opcode Caching is disabled for CLI
    
    Directive => Local Value => Master Value
    opcache.enable => On => On
    opcache.use_cwd => On => On
    opcache.validate_timestamps => On => On
    opcache.validate_permission => Off => Off
    opcache.validate_root => Off => Off
    opcache.dups_fix => Off => Off
    opcache.revalidate_path => Off => Off
    opcache.log_verbosity_level => 1 => 1
    opcache.memory_consumption => 800 => 800
    opcache.interned_strings_buffer => 8 => 8
    opcache.max_accelerated_files => 65407 => 65407
    opcache.max_wasted_percentage => 5 => 5
    opcache.consistency_checks => 0 => 0
    opcache.force_restart_timeout => 180 => 180
    opcache.revalidate_freq => 180 => 180
    opcache.file_update_protection => 2 => 2
    opcache.preferred_memory_model => no value => no value
    opcache.blacklist_filename => no value => no value
    opcache.max_file_size => 0 => 0
    opcache.protect_memory => 0 => 0
    opcache.save_comments => 1 => 1
    opcache.optimization_level => 0x7FFEBFFF => 0x7FFEBFFF
    opcache.opt_debug_level => 0 => 0
    opcache.enable_file_override => On => On
    opcache.enable_cli => Off => Off
    opcache.error_log => no value => no value
    opcache.restrict_api => no value => no value
    opcache.lockfile_path => /tmp => /tmp
    opcache.file_cache => no value => no value
    opcache.file_cache_only => 0 => 0
    opcache.file_cache_consistency_checks => 1 => 1
    opcache.huge_code_pages => Off => Off
    opcache.preload => no value => no value
    opcache.preload_user => no value => no value
    

    SSH command to list all custom PHP .ini settings files
    Code (Text):
    php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: /etc/centminmod/php.d
    Additional .ini files parsed:      /etc/centminmod/php.d/a_customphp.ini,
    /etc/centminmod/php.d/curlcainfo.ini,
    /etc/centminmod/php.d/geoip.ini,
    /etc/centminmod/php.d/igbinary.ini,
    /etc/centminmod/php.d/mailparse.ini,
    /etc/centminmod/php.d/maxminddb.ini,
    /etc/centminmod/php.d/mcrypt.ini,
    /etc/centminmod/php.d/mysqlnd.ini,
    /etc/centminmod/php.d/preload.ini,
    /etc/centminmod/php.d/redis.ini,
    /etc/centminmod/php.d/timezonedb.ini,
    /etc/centminmod/php.d/zendopcache.ini,
    /etc/centminmod/php.d/zz-zendopcache.ini,
    
    Contents of /etc/centminmod/php.d/zendopcache.ini
    Code (Text):
    zend_extension=opcache.so
    ;opcache.error_log=/var/log/php_opcache_error.log
    opcache.enable=1
    opcache.memory_consumption=80
    opcache.interned_strings_buffer=8
    opcache.max_wasted_percentage=5
    opcache.max_accelerated_files=65407
    ; http://php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
    ; defaults to zend opcache checking every 180 seconds for PHP file changes
    ; set to zero to check every second if you are doing alot of frequent
    ; php file edits/developer work
    ; opcache.revalidate_freq=0
    opcache.revalidate_freq=180
    opcache.fast_shutdown=0
    opcache.enable_cli=0
    opcache.save_comments=1
    opcache.enable_file_override=1
    opcache.validate_timestamps=1
    opcache.huge_code_pages=0
    
    To perserve and override Zend Opcache settings I created an alphanumeric file that comes after the default file name at /etc/centminmod/php.d/zz-zendopcache.ini which has contents of
    Code (Text):
    opcache.memory_consumption=800
    opcache.interned_strings_buffer=8
    opcache.max_wasted_percentage=5
    opcache.max_accelerated_files=65407
    ; http://php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
    ; defaults to zend opcache checking every 180 seconds for PHP file changes
    ; set to zero to check every second if you are doing alot of frequent
    ; php file edits/developer work
    ; opcache.revalidate_freq=0
    opcache.revalidate_freq=180
    opcache.fast_shutdown=0
    opcache.enable_cli=0
    opcache.save_comments=1
    opcache.enable_file_override=1
    opcache.validate_timestamps=1
    ;opcache.huge_code_pages=1
    

    Wordpress OpCache Plugin Install



    To test Wordpress Opcache plugin you can manually install it on your server either via Wordpress Admin add new plugin section. Or via below SSH commands - yes no need for FTP or Wordpress Admin GUI really :)

    To install via SSH command line, run below commands replacing yourdomain.com in vhostname variable with your actual Wordpress Nginx site domain corresponding with your Wordpress install directory path i.e. if you installed Wordpress at yourdomain.com, then web install path would be /home/nginx/domains/yourdomain.com/public.
    Code (Text):
    vhostname=yourdomain.com
    cd /home/nginx/domains/${vhostname}/public
    wp plugin install flush-opcache --activate --allow-root
    wp option update flush-opcache-upgrade 1 --allow-root
    chown -R nginx:nginx /home/nginx/domains/${vhostname}/public/wp-content/plugins/
    nprestart
    wp plugin list --allow-root
    

    List your Wordpress installs plugins and their version and status
    Code (Text):
    wp plugin list --allow-root
    +------------------+----------+--------+---------+
    | name             | status   | update | version |
    +------------------+----------+--------+---------+
    | akismet          | inactive | none   | 4.1.4   |
    | autoptimize      | active   | none   | 2.6.2   |
    | autoptimize-gzip | active   | none   | 0.1     |
    | cdn-enabler      | active   | none   | 1.0.9   |
    | classic-editor   | active   | none   | 1.5     |
    | disable-xml-rpc  | active   | none   | 1.0.1   |
    | native-lazyload  | active   | none   | 1.0.2   |
    | nginx-helper     | active   | none   | 2.2.1   |
    | sucuri-scanner   | active   | none   | 1.8.24  |
    | flush-opcache    | active   | none   | 3.0.2   |
    +------------------+----------+--------+---------+
    
    The Wordpress OpCache plugin only has two options to hide flush menu button and to toggle flush OpCache on Wordpress upgrades automatically.
    Code (Text):
    wp option list --search=flush-opcache-*  --allow-root
    +---------------------------+--------------+
    | option_name               | option_value |
    +---------------------------+--------------+
    | flush-opcache-hide-button |              |
    | flush-opcache-upgrade     | 1            |
    +---------------------------+--------------+
    

    Wordpress OpCache Plugin Settings & Zend OpCache Statistics



    flush-opcache-plugin-settings-01.png
    flush-opcache-plugin-stats-01.png

    So let me know how does your install testing go for Wordpress OpCache plugin and whether you want it auto installed with centmin.sh menu option 22 Wordpress auto installs ? :)

    Reason I plan on adding this is due to Wordpress upgrades modifying and updating PHP scripts, so Zend Opcache having to wait 180 seconds to detect changes can mess with some PHP updated functions unless you do a PHP-FPM service restart to flush Zend Opcache cache. Installing this plugin and enabling flush OpCache cache on Wordpress update, will solve this problem hopefully :)
     
  2. adzkii

    adzkii Member

    38
    1
    8
    Apr 15, 2020
    Ratings:
    +3
    Local Time:
    11:23 AM
    Opcode Caching => Disabled
    Optimization => Disabled
    why does it show disabled, how can we enable these
     
  3. eva2000

    eva2000 Administrator Staff Member

    45,183
    10,276
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,926
    Local Time:
    8:23 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    SSH command line PHP has opcache disabled on purpose to prevent issues via ini settings option opcache.enable_cli=0. If you want to enable it for SSH command line ran PHP, you can create a custom .ini settings file to override opcache.enable_cli=1 as outlined at PHP-FPM - CentminMod.com LEMP Nginx web stack for CentOS. Just like I did in above custom override ini settings file mentioned at /etc/centminmod/php.d/zz-zendopcache.ini

    You only need to care about non-SSH command PHP i.e. your web apps if you use phpinfo php page viewed in browser you will see Opcache enabled. When run command via SSH it is disabled for command line PHP only.