How to get PHP scripts working in HTML files
You
can't run PHP in .html files because the server does not recognize that as a
valid PHP extension unless you tell it to. To do this First, create a blank
text file and name it ".htaccess" file in your root web directory and
add this line to it:
AddType application/x-httpd-php
.htm .html
This
will tell Apache to process files with an .htm or .html file extension as PHP
files.Next, open the file with a simple text editor like the "vi
Editor" and Paste the following line into the file
AddType application/x-httpd-php
.html .htm
If
this does not work, please remove the line above from your file and paste this
alternative line into it, for PHP5:
AddType application/x-httpd-php5
.html .htm
Now
Create a file named hellotest.html and put it in your web server's root
directory (DOCUMENT_ROOT) with the following content:
Example
#1 our first PHP script: hellotest.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello
World</p>'; ?>
</body>
</html>
Try to
open the file in your browser by typing in:
http://www.your-domain.com/hellotest.html
Comments