How We Prevent WordFence Fatal Error After Migration

Why WordFence Throws a Fatal Error After Migration

When you created a staging site on another server or moved your entire website to another domain, it sometimes leads to a fatal error, and your migrated website does not work.

This can happen if the WordFence plugin is installed and its Web Application Firewall (WAF) has been activated.

The reason for this fatal error is that on activating the WordFence firewall, WordFence generates a .user.ini file at the root of your WordPress installation and this ini file contains the absolute path to the PHP file wordfence-waf.php.

After cloning into a staging site or migrating your website to another host, the .user.ini still contains a link to the absolute path of the original website’s wordfence-waf.php.

If the path to that file changed or the file is not available any more on the original website, WordFence will throw a fatal error and your WordPress website fails to load.

To avoid this error, newer versions of WP STAGING rename the .user.ini to .user.ini.bak on all cloned websites.

Due to renaming of the user.ini, the WordFence application firewall does not work properly anymore on the staging site. This is usually no problem. You can even push the staging site to live and the firewall setting on the live site will not be affected.

How to Activate WordFence Web Application Firewall on the Staging Site

  1. Edit the file user.ini.bak and change the path to wordfence-waf.php according to the absolute root path of your website.
  2. Rename the file user.ini.bak to user.ini

Updated on October 21, 2022