LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-23-2003, 03:17 PM   #1
NW Otter
LQ Newbie
 
Registered: Sep 2003
Distribution: Mandrake
Posts: 27

Rep: Reputation: 15
Question php in an .html file does not work


I am just starting to experiment with Apache, php and mysql. I have written a bit of asp, vbscipt and SQL server, though.

I have a mandrake box with php and mysql installed but I don't know if they are configured correctly, and may not be due to this problem. I have this code...

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>Hello, world</title>
</head>
<body bgcolor="#ffffff">
<h1>
<?php
echo "Hello, world";
?>
</h1>
</body>
</html>

If I put it on the web server as example.php and look in a browser, (IE on a windows box) it works. If I change the filename to example.html, it does NOT work. What gives?
 
Old 09-23-2003, 03:24 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Apache will only parse certain files for php commands - eg .php extenstions by default. You will need to modify the AddType directive to include .html files if you want them to be parsed too.
 
Old 09-23-2003, 03:29 PM   #3
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
There is a line in httpd.conf that looks like:

Code:
AddType application/x-httpd-php .php
This line basically tells apache to run a file with a .php extension through the php interpreter. If you want plain .html files to be interpreted as php you will have to add .html to the end of this line.

This can be useful for hiding the fact that you use php to the casual observer...but also there is a performance penalty, because every plain html page has the added overhead of being sent through the interpreter.

Another thing you can do though...is create your own custom file extensions here. For example, if your entire website is done in php you can name all your files index.joe or index.bob or index.uselinuxordie, well, you get the idea.
 
Old 09-23-2003, 03:59 PM   #4
NW Otter
LQ Newbie
 
Registered: Sep 2003
Distribution: Mandrake
Posts: 27

Original Poster
Rep: Reputation: 15
Thanks for the help. I figured it was some sort of configuration problem, but tracking stuff like this down in documentation can be time consuming.

Thanks again!
 
Old 09-23-2003, 04:10 PM   #5
Vampyric
LQ Newbie
 
Registered: Mar 2003
Posts: 27

Rep: Reputation: 15
you also might want to check that the php module is not commented out in httpd.conf (cause it is by default)

uncomment

LoadModule php4_module /usr/lib/apache/1.3/libphp4.so

assuming you installed php4

and start the server
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
html into php charnel Programming 7 08-30-2005 10:47 AM
php in html code blizunt7 Programming 5 06-15-2005 01:08 PM
html to php? help me please!!!!! trscookie Programming 4 01-24-2005 06:36 AM
Konqueror + file:/usr/share/doc/HTML/index.html jon_k Linux - Software 2 11-25-2003 05:06 AM
html file doesn't work rsarson General 9 09-27-2003 09:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration