Fixing "Failed Opening Required wordfence-waf.php" — Restore or Recreate the File
If your WordPress website displays the "Failed Opening Required wordfence-waf.php" error, it means the Wordfence Web Application Firewall (WAF) file is missing, corrupted, or has incorrect permissions. The closely related fatal-error and not-found variants are covered in Fixing wordfence-waf.php Fatal Error in WordPress and Fixing "wordfence-waf.php Not Found" Error in WordPress; for the manual recreate procedure, see How to Recreate wordfence-waf.php Manually in WordPress.
PHP Fatal error: require_once(/home/user/public_html/wordfence-waf.php):
failed to open stream: No such file or directory
indicates that Wordfence's Web Application Firewall (WAF) is missing or corrupted.
Check If wordfence-waf.php Exists
Run:
ls -lah /home/user/public_html/wordfence-waf.php
If the file does not exist, proceed to restore or recreate it.
Restore wordfence-waf.php from Backup
If you have a backup of your WordPress site, restore the wordfence-waf.php file from:
- cPanel > File Manager
- Your hosting provider's backup system
- A manual backup (FTP, cPanel, SSH)
If the file is restored, restart Apache/Nginx:
sudo systemctl restart apache2
or
sudo systemctl restart nginx
Recreate wordfence-waf.php Manually
If the file cannot be restored, recreate it.
Create a New wordfence-waf.php
- Connect via SSH or use cPanel File Manager
- Create the file manually:
nano /home/user/public_html/wordfence-waf.php - Add the following content:
<?php // Wordfence Web Application Firewall if (file_exists(__DIR__ . '/wp-content/wflogs/bootstrap.php')) { include_once __DIR__ . '/wp-content/wflogs/bootstrap.php'; } - Save the file (CTRL + X, then Y, then ENTER).
Set correct permissions:
chmod 644 /home/user/public_html/wordfence-waf.php
chown www-data:www-data /home/user/public_html/wordfence-waf.php # For Apache
chown nginx:nginx /home/user/public_html/wordfence-waf.php # For Nginx
Restart Apache/Nginx
sudo systemctl restart apache2
or
sudo systemctl restart nginx
Check & Update wp-config.php
If wordfence-waf.php is still missing, check your wp-config.php file.
- Open
wp-config.phpfor editing:nano /home/user/public_html/wp-config.php - Find this line (or add it if missing):
define("WFWAF_LOG_PATH", '/home/user/public_html/wp-content/wflogs/'); - Save the file & exit.
Try loading your site again.
Reinstall Wordfence (If Necessary)
If Wordfence is still broken, reinstall it:
wp plugin deactivate wordfence
wp plugin delete wordfence
wp plugin install wordfence --activate
Now Wordfence WAF should work properly!
Summary of Fixes
| Issue | Fix |
|---|---|
| File missing | Restore from backup or recreate manually |
| Permissions incorrect | Set chmod 644 and chown www-data:www-data |
| Wrong wp-config.php settings | Add define("WFWAF_LOG_PATH", ...) |
| Wordfence corrupted | Reinstall with wp plugin install wordfence |
Now Wordfence WAF should be working again!
