LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 01-26-2004, 06:22 PM   #1
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Rep: Reputation: 30
Set up Apache to read php IN html code?


Hi guys,

I know a reasonable amount about Apache, but am no expert. Have a question for you. My Apache server is running on linux. All of my pages on my site are .html extensions (except for a few .php pages. Recently, I started learning php. One thing I tried was to put php code INTO html. When I did this and tried to view the site, the php code would actually show up ON the site in the browser. I have been told that:
Quote:
"PHP has to be in pages that end with the .php extension, unless your server is set up to run .html pages through the parser. Most shared hosting is set up to only process php scripting in .php, .php3 and .php4 pages."
I'll look into it, but what exactly does that mean, and what do I have to do in httpd.conf to allow php code to run in html? Thanks!

Chris
 
Old 01-27-2004, 04:54 AM   #2
leckie
Member
 
Registered: Dec 2003
Location: Australia
Distribution: Mandrake 9.2
Posts: 151

Rep: Reputation: 30
gee i didn't think u had to do anything, unlike perl.
So does php work at all, do pages with .php extentions work.
if so inline php should work as well.
but u cannot just start coding u have to encapsulate it eg
<?php echo "Hello World<P>"; ?>
 
Old 01-27-2004, 05:46 AM   #3
GraemeK
Member
 
Registered: Aug 2003
Location: Essex, UK
Distribution: Windoze 2000, Fedora Core 3
Posts: 325

Rep: Reputation: 30
what does

<?
phpinfo();
?>

show? i.e create a html file and put the above code in it. then name the file index.php and stick it in your apache root.

you should see tones of info about your php system.

if not php aint working!
 
Old 01-27-2004, 07:43 AM   #4
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Thanks for the replies, guys. I DO see pages ending in .php, and I know php is installed and working correctly. What's NOT working is when I have an html page with php code IN the html code. When that happens, the php code is displayed on the page itself. The only advice I've been able to find is what I quoted in my original post.

What I mean is this:
Quote:
show? i.e create a html file and put the above code in it. then name the file index.php and stick it in your apache root.
I have that already. The php install automatically generated it. BUT, if I create a HTML extension file and place all that php code into it, then that WON'T work. The files are identical, except one ends in .php and one ends in .html. The .php works, the .html (with php code IN it) doesn't.

Chris
 
Old 01-27-2004, 07:50 AM   #5
leckie
Member
 
Registered: Dec 2003
Location: Australia
Distribution: Mandrake 9.2
Posts: 151

Rep: Reputation: 30
can u put
<body>
<?php echo "Hello World<P>"; ?>
</body>
into a file called test.html

what does it do
 
Old 01-27-2004, 08:52 AM   #6
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Hello again.

If I do that, it shows all the code in the browser itself. I attached a screenshot for you to see. If I then change the filename to "test.php", though, it displays only "Hello World" as it should.

http://www.bartlett-family.net/quiz/image1.jpg

The file itself is here. The same file (but with a php extension) is here.

Chris

Last edited by WorldBuilder; 01-27-2004 at 08:55 AM.
 
Old 01-27-2004, 09:01 AM   #7
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
In addition, I've been reading up on this. I already added:
Code:
AddType application/x-httpd-php .php .html
to my httpd.conf file. I believe that this should allow php code INSIDE html files. I have also read that I have to add "ScriptAlias" something or other to the httpd.conf file. For instance, I had to add:
Code:
ScriptAlias /cgi-bin/ "/blah/blah/blah/cgi-bin/"
to allow for cgi files. The problem with that is that php files are not all in one directory as cgi files are! How can I add this ScriptAlias line to the httpd.conf with more than one directory accessible? Should I just make the directory my DocumentRoot directory with a trailing "/"?

Chris
 
Old 01-27-2004, 09:38 AM   #8
GraemeK
Member
 
Registered: Aug 2003
Location: Essex, UK
Distribution: Windoze 2000, Fedora Core 3
Posts: 325

Rep: Reputation: 30
You could have a html file ending in .php and if no php code was in it then the file would be ouputed as is. if the html file had <?php ?> then what ever is in those brackets will be passed to the php pasher where the code would be interupted.
 
Old 01-27-2004, 09:53 AM   #9
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by GraemeK
You could have a html file ending in .php and if no php code was in it then the file would be ouputed as is. if the html file had <?php ?> then what ever is in those brackets will be passed to the php pasher where the code would be interupted.
Huh? Sorry, I don't understand what you're saying. All I want to do is allow php code inside .html files. There seems to be some setting in Apache's httpd.conf file I have to change, but I don't know what it is. Something to do with a parser...?
 
Old 01-27-2004, 11:25 AM   #10
GraemeK
Member
 
Registered: Aug 2003
Location: Essex, UK
Distribution: Windoze 2000, Fedora Core 3
Posts: 325

Rep: Reputation: 30
as far as i know any html file that contains php data has to end in .php in order to be pased to the php parser and outputed.

getting php code outputed correctly and still retaining the .html extension isnt possible i didnt think.
 
Old 01-27-2004, 12:16 PM   #11
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by GraemeK
as far as i know any html file that contains php data has to end in .php in order to be pased to the php parser and outputed.

getting php code outputed correctly and still retaining the .html extension isnt possible i didnt think.
It is possible. Actually, I just figured it out! You have to add the above-mentioned lines to httpd.conf as well as:
Code:
AddHandler php-script .php .html
Now, you can add php code to html files and have it execute as if it were a regular php file. Cool!

Chris
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
php in html code blizunt7 Programming 5 06-15-2005 01:08 PM
How do I set a PHP variable = to a HTML textbox's value? nickiv Programming 4 06-06-2005 01:41 PM
Apache displays html code tlmii Linux - Software 3 06-09-2004 11:07 AM
In apache, i want to set my default page to be index.html, or something thep Linux - Newbie 3 04-17-2001 02:27 AM


All times are GMT -5. The time now is 09:27 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration