Why is this needed?
HTML is the plain language of web pages. PHP is a programming language that makes pages smart, for example by showing today's date. The server treats the two differently. It only runs PHP in files that end in .php.
If you put PHP code inside a .html file, the server just shows it as text. A setting in the .htaccess file can change that. A .htaccess file is a small settings file for the Apache web server.
Warning: A wrong line in .htaccess can cause a 500 error and take your site down. Download a copy of the file before you edit.
Steps
- Log in to your hosting control panel.
- Open File Manager.
- Click Settings and tick Show Hidden Files (dotfiles).
- Go to the folder of your website, usually
public_html. - Find
.htaccess. If it is not there, click + File and create it. - Download a copy as a backup.
- Right-click it and choose Edit.
- Add one of the following blocks at the end. Which one works depends on how PHP is set up on your plan.
This tells Apache to treat HTML files as PHP. On some servers you need a version-specific line, like:AddType application/x-httpd-php .html .htm
Hostvento support can tell you the right handler name for your plan. If you use cPanel's MultiPHP Manager, a handler line may be added there for you.AddHandler application/x-httpd-php81 .html .htm - Click Save Changes.
Test it
- Create a file named
test.htmlinpublic_html. - Put this inside it:
<?php echo "PHP works"; ?> - Open
https://yourdomain.com/test.html. - If you see the words "PHP works", it is on. If you see the code, it is not.
- Delete the test file afterwards.
Things to know
- Every .html file is now sent through PHP. This can slow a very big site slightly.
- If the browser downloads the file instead of showing it, remove the line and ask support for the correct handler.
Quick recap
- By default only .php files run PHP.
- Add an
AddTypeorAddHandlerline in .htaccess. - Back up first.
- Test with a small file.