Running PHP code in a file with an .html extension
source link: https://help.dreamhost.com/hc/en-us/articles/360037073252-Running-PHP-code-in-a-file-with-an-html-extension
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Running PHP code in a file with an .html extension
Overview
Normally, when PHP and HTML are combined in the same file, the file uses a .php extension and displays data in the browser.
However, if you need to place PHP code in a file with an .html extension, you must add a Handler to your .htaccess file.
Code to add to your .htaccess file
View the following articles for instructions on how to edit files using an FTP or SSH client.
The file you need to add code to is named .htaccess. If this doesn't exist in your website's home directory, use the articles above to create it. Add the following line to the .htaccess file, depending on which version of Linux your site is running on.
If your site is on a server running Ubuntu 18
You can add either of the following.
AddHandler php-cgi .html
AddHandler php5-cgi .html
If your site is on a server running Ubuntu 14
Only the following will work.
AddHandler php5-cgi .html
This line of code allows files with .html extensions to run PHP code in your browser.
Did this article answer your questions?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK