Based on your description, you're correct that the standard way to force Apache to parse .html files (and optionally .htm files) as PHP is to add a directive to your site's .htaccess file. However, since you're using cPanel, we need to be careful about how we do this to avoid conflicting with (or accidentally editing) the cPanel-generated PHP handler block. I'll explain why this is an issue and provide a safe, step-by-step solution below.
Why the "Do Not Edit" Warning Matters
- cPanel (via tools like MultiPHP Manager or EasyApache) automatically generates and manages the PHP handler configuration in your
.htaccess file (or sometimes in the server's main Apache config). This is what the # php -- BEGIN cPanel-generated handler, do not edit comment is protecting.
- If you edit inside that block, your changes could be overwritten the next time cPanel updates the PHP configuration (e.g., if you change PHP versions or if the server restarts/rebuilds configs).
- The good news: You can safely add custom directives outside of that block (e.g., at the beginning or end of the file). Apache will still process them.
Recommended Solution: Edit .htaccess Safely
You can add the necessary directive to your .htaccess file via cPanel's File Manager (or via FTP/SSH if you prefer). Here's how:
-
Log in to cPanel:
- Go to your cPanel dashboard.
- Navigate to Files > File Manager.
- Browse to the directory where your site's
.htaccess file is located (usually the root of your domain, like /public_html/ or a subdomain's folder). If .htaccess doesn't exist, create a new file with that name.
-
Edit the .htaccess File:
- Right-click
.htaccess and select Edit (or open it in the built-in editor).
- Look for the cPanel-generated block. It will look something like this (the exact content depends on your PHP version and setup):
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
- Do not edit anything inside this block!
-
Add Your Custom Directive:
-
Add the following line outside the cPanel block—I recommend adding it at the very end of the file to avoid any potential conflicts. This tells Apache to treat .html (and optionally .htm) files as PHP:
AddType application/x-httpd-php .html .htm
-
Full example of what your .htaccess might look like after the change:
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# My custom handler for HTML files
AddType application/x-httpd-php .html .htm
-
Save and Test:
Important Notes and Troubleshooting
- Performance Impact: Parsing all
.html files as PHP can slow down your site slightly (since static HTML is faster than PHP-processed files). Only do this if you truly need PHP in your HTML files (e.g., for dynamic content). Consider renaming files to .php instead if possible.
- If It Doesn't Work:
- Security: This change means any
.html file could execute PHP code, which is a potential security risk if untrusted users can upload files. Monitor your site closely.
- Alternatives to .htaccess:
- If you have access to the full Apache config (via WHM or root SSH), you could add this globally, but that's overkill for most users.
- In cPanel, go to Domains > Apache Handlers (under Advanced) and add a custom handler there (e.g., extension
.html handled by application/x-httpd-php). This is a GUI way to do it without editing files, but it may not always work for PHP extensions—test it.
- Reverting Changes: If something goes wrong, just delete the line you added from
.htaccess and save.
If this doesn't work or you run into errors (e.g., 500 Internal Server Error), provide more details like your exact PHP version, the full content of the cPanel-generated block, or any error messages, and I can refine the advice. If you're not comfortable editing files, your host's support can usually help with this.