MySQLi storage engine

In Wordfence 7.4.0, an alternate storage engine has been added to the Web Application Firewall, so that sites can store firewall data in the mysql database instead of using files in wp-content/wflogs/.

We only recommend using this option if your site is unable to read and write the firewall files consistently or if your host uses multiple web servers that do not share the same filesystem, since better performance and efficient resource usage are likely when using the default file-based storage on most hosts. Some examples where using the MySQLi storage engine may be useful include:

  • Multiple web servers behind a load balancer, without a shared filesystem
  • Servers where some paths are not always writable, including wp-content/wflogs/
  • Servers where file locking is not enforced on NFS filesystems
  • Auto-scaling servers without a shared filesystem

This change is automatic on hosting at WP Engine, since the file-based method is not compatible with their configuration.

On other hosts, you will need to add this to your wordfence-waf.php: define('WFWAF_STORAGE_ENGINE', 'mysqli'); If you have not optimized the firewall, you could add the line to wp-config.php as described on our constants help page instead.

For example, in wordfence-waf.php, the line should be added after the opening PHP tag, but before any other code:
<?php
// Before removing this file, please verify the PHP ini setting `auto_prepend_file` does not point to this.
define('WFWAF_STORAGE_ENGINE', 'mysqli');
 
if (file_exists('<path to wordpress>/wp-content/plugins/wordfence/waf/bootstrap.php')) {
    define("WFWAF_LOG_PATH", '<path to wordpress>/wp-content/wflogs/');
    include_once '<path to wordpress>/wp-content/plugins/wordfence/waf/bootstrap.php';
}

After this change is made, the firewall will start with fresh settings. You may need to switch from “Learning Mode” to “Enabled and Protecting” on the Firewall Options page if you want to skip Learning Mode. Otherwise, Learning Mode will run for one week as it does in a new installation.