Learn about Centmin Mod LEMP Stack today
Register Now

PHP-FPM Can't undo functions.php edit

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Jon Snow, Nov 1, 2023.

  1. Jon Snow

    Jon Snow Active Member

    757
    155
    43
    Jun 30, 2017
    Ratings:
    +222
    Local Time:
    3:56 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Self-installed Wordpress on Centminmod stable (IP proxied by Cloudflare).

    I added a piece of code to my functions.php file to give a Role a permission they shouldn't have from Core Wordpress. It worked but I can't undo this change (removing the code and saving functions.php file).
    • Problem started on PHP 8.0 and even when upgrading to 8.1, nothing changed.
    • I've tried restarting PHP FPM to clear OPCACHE but it didn't work.
    • I've tried reloading PHP FPM with service php-fpm reload
    • I tried clearing Cloudflare cache from the CF Control Panel, didn't work.
    • I even tried flushing Redis cache via CLI even tho I don't use a Redis plugin just to see.
    Not sure what's going on.


    Using all three of these in my vhost config:
    Code (Text):
    Server (443) context:
      include /usr/local/nginx/conf/cloudflare.conf;
    
    Location context:
      include /usr/local/nginx/conf/wpsecure.conf;
      include /usr/local/nginx/conf/wpnocache.conf;

    I still have to try switching Wordpress themes but that's a last resort in case I lose anything.
     
    Last edited: Nov 1, 2023
  2. eva2000

    eva2000 Administrator Staff Member

    52,729
    12,074
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,601
    Local Time:
    4:56 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    How are you editing the PHP files? via SSH using nano or VIM linux text editor?

    Ensure the file permissions are correct - especially if you edited the PHP files by downloading and uploading edited files via pure-ftpd or SFTP as root user

    Code (Text):
    chown -R nginx:nginx /home/nginx/domains/yourdomain.com/public
    
     
  3. Jon Snow

    Jon Snow Active Member

    757
    155
    43
    Jun 30, 2017
    Ratings:
    +222
    Local Time:
    3:56 PM
    Nginx 1.13.9
    MariaDB 10.1.31
    Filezilla.
    It is correct. It belongs to nginx.

    I can see the changes in functions.php (the save goes through). I just don't see the changes reflected in the WP Admin Panel.
     
  4. eva2000

    eva2000 Administrator Staff Member

    52,729
    12,074
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,601
    Local Time:
    4:56 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    If the file is php then it could be Zend Opcache related, the default revalidate frequency is 180 seconds so if you edit a PHP file within 180 seconds, you may not see the update shown. If you want to see it immediately, do a PHP-FPM service restart = fpmrestart
    You can check with command
    Code (Text):
    php --ri 'Zend OPcache'

    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.inherited_hack => On => On
    opcache.dups_fix => Off => Off
    opcache.revalidate_path => Off => Off
    opcache.log_verbosity_level => 1 => 1
    opcache.memory_consumption => 64 => 64
    opcache.interned_strings_buffer => 8 => 8
    opcache.max_accelerated_files => 8000 => 8000
    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.fast_shutdown => 1 => 1
    opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
    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


    You can exclude a file or path from Zend Opcache caching completely via blacklist option too
    To customise Zend Opcache settings see the instructions to create your own .ini settings file to retain the changes at https://centminmod.com/phpfpm.html#customphpini

    Example order of php .ini files applied via php --ini command
    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/imagick.ini,
    /etc/centminmod/php.d/mailparse.ini,
    /etc/centminmod/php.d/memcache.ini,
    /etc/centminmod/php.d/memcached.ini,
    /etc/centminmod/php.d/redis.ini,
    /etc/centminmod/php.d/zendopcache.ini

    If i want to override opcache.revalidate_freq 180 seconds default, I'd create a .ini file after /etc/centminmod/php.d/zendopcache.ini alphabetically i.e. /etc/centminmod/php.d/zzendopcache.ini

    So ordered after zendopcache.ini
    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/imagick.ini,
    /etc/centminmod/php.d/mailparse.ini,
    /etc/centminmod/php.d/memcache.ini,
    /etc/centminmod/php.d/memcached.ini,
    /etc/centminmod/php.d/redis.ini,
    /etc/centminmod/php.d/zendopcache.ini,
    /etc/centminmod/php.d/zzendopcache.ini


    In /etc/centminmod/php.d/zzendopcache.ini add value say 10 seconds
    Code (Text):
    opcache.revalidate_freq = 10


    Note though reducing revalidation frequency lowers performance of caching all the time 24/7. Best way is just to restart php-fpm and nginx after file updates which are done manually via command shortcut
    Code (Text):
    nprestart

    After restart recheck value is now at 10 seconds
    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.inherited_hack => On => On
    opcache.dups_fix => Off => Off
    opcache.revalidate_path => Off => Off
    opcache.log_verbosity_level => 1 => 1
    opcache.memory_consumption => 64 => 64
    opcache.interned_strings_buffer => 8 => 8
    opcache.max_accelerated_files => 8000 => 8000
    opcache.max_wasted_percentage => 5 => 5
    opcache.consistency_checks => 0 => 0
    opcache.force_restart_timeout => 180 => 180
    opcache.revalidate_freq => 10 => 10
    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.fast_shutdown => 1 => 1
    opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
    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

    Any php related setting can override and customised this way as well :)