If you’ve encountered the error:
Invalid command 'RequestHeader', perhaps misspelled or defined by a module not included in the server configuration
don’t worry this is a common issue, especially for developers working with Apache servers.
In this guide, we’ll walk you through exactly why this error happens and how to fix it quickly, even if you’re not a server expert.
What Does “Invalid Command ‘RequestHeader’” Mean?
This error typically appears when your server does not recognize the RequestHeader directive.
In most cases, it means:
- The required Apache module is not enabled
- The module is not installed
- Your server configuration is missing necessary permissions
Why This Error Happens
Before jumping into fixes, it’s important to understand the root cause.
1. mod_headers Module Is Disabled
The RequestHeader directive belongs to the mod_headers module in Apache. If this module isn’t enabled, the server won’t recognize the command.
2. Apache Configuration Issues
Sometimes, even if the module exists, it may not be properly loaded in your configuration file.
3. Hosting Restrictions
On shared hosting, certain modules may be restricted or disabled by default.
How to Fix “Invalid Command ‘RequestHeader’” (Step-by-Step)
Step 1 Enable mod_headers Module
If you’re using Apache on Linux:
sudo a2enmod headers
Then restart Apache:
sudo systemctl restart apache2
Step 2 Check Apache Configuration File
Open your Apache config file:
sudo nano /etc/apache2/apache2.conf
Make sure this line exists:
LoadModule headers_module modules/mod_headers.so
If it’s missing, add it manually.
Step 3 Restart Your Server
After making changes, always restart Apache:
sudo systemctl restart apache2
Step 4 Verify Module Is Enabled
Run:
apache2ctl -M | grep headers
If you see:
headers_module (shared)
you’re good to go.
Fix for XAMPP or Localhost Users
If you’re using XAMPP:
- Open httpd.conf
- Find this line:
#LoadModule headers_module modules/mod_headers.so
- Remove the
#to uncomment it:
LoadModule headers_module modules/mod_headers.so
- Restart Apache from XAMPP control panel
Fix for Shared Hosting (cPanel Users)
If you’re on shared hosting:
- Check if mod_headers is enabled via cPanel → Select PHP Version → Extensions
- If not available, contact your hosting provider
Common Mistakes to Avoid
- Forgetting to restart Apache after changes
- Editing the wrong configuration file
- Using
.htaccesswithout proper permissions - Assuming module is enabled without verifying
Pro Tip for Developers
If you’re frequently working with headers, ensure your .htaccess file includes proper conditions:
<IfModule mod_headers.c>
RequestHeader set X-Forwarded-Proto "https"
</IfModule>
This prevents errors if the module isn’t loaded.
Final Thoughts
The “Invalid command ‘RequestHeader’” error may look intimidating, but it’s usually a simple fix.
In most cases, enabling the mod_headers module resolves the issue instantly.
If you follow the steps above, your server should be up and running without any problems.
FAQs
Is this error only related to Apache?
Yes, this specific directive is part of Apache. Other servers like Nginx use different configurations.
Can I fix this without root access?
If you’re on shared hosting, you’ll likely need help from your hosting provider.
Why does it work locally but not on live server?
Because your local environment (like XAMPP) may have modules enabled by default, while your live server does not.