LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2010, 04:28 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
php not running in html page


Hi group,

I have an HTML page that I want to run some PHP code. I found several "How tos" about this but I can't get it to work. The code is very simple:
Code:
cat  test.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>Test</title>
  <meta content="william estrada" name="author">
</head>
<body style="background-color: rgb(204, 204, 204); color: windowtext;"
 link="#0000ee" vlink="#551a8b" alink="#ee0000">
<center>
<?php
echo "Last modified: " . date ("F d Y", getlastmod());
?>
</body>
</html>
What am I missing??

Thanks for your time.
 
Old 05-22-2010, 06:11 PM   #2
Fingers of Fudge
LQ Newbie
 
Registered: Aug 2007
Distribution: Slackware 13.0
Posts: 14

Rep: Reputation: 1
Did you enable/set up php in apache?
 
Old 05-22-2010, 06:29 PM   #3
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Manjaro
Posts: 1,791

Rep: Reputation: 427Reputation: 427Reputation: 427Reputation: 427Reputation: 427
Code:
sudo yum install php
or
Code:
sudo apt-get install php
depending on your distro
 
Old 05-22-2010, 06:56 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Once you have apache set up correctly you need to access the page through apache. So don't try to view the page directly in your web browser but access through a proper URL which will make the web service (apache) serve up the page after having processed the php.
 
Old 05-22-2010, 07:23 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Usually Apache does not put files through the php interpreter unless they have the .php extension.

It is, however, possible to make Apache run .html files.
 
Old 05-23-2010, 01:16 PM   #6
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by RockDoctor View Post
Code:
sudo yum install php
or
Code:
sudo apt-get install php
depending on your distro
I have these installed:
Code:
Installed Packages
php.i686                                           5.3.2-2.fc12         @updates
php-cli.i686                                       5.3.2-2.fc12         @updates
php-common.i686                                    5.3.2-2.fc12         @updates
php-ldap.i686                                      5.3.2-2.fc12         @updates
php-mysql.i686                                     5.3.2-2.fc12         @updates
php-pdo.i686                                       5.3.2-2.fc12         @updates
 
Old 05-23-2010, 01:19 PM   #7
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by Fingers of Fudge View Post
Did you enable/set up php in apache?
How do I do that?? I am sure that is the problem. Should be on by default??? I added this to httpd.conf:
Code:
AddType application/x-httpd-php .php
 
Old 05-25-2010, 03:51 AM   #8
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Lightbulb

I was also facing a similar problem, see this.
 
Old 05-25-2010, 04:29 AM   #9
webhope
Member
 
Registered: Apr 2010
Posts: 184

Rep: Reputation: 30
I just wonder why you use .html extension. I am used to use .php for php code, and I am not sure if php can run in .html file (be parsed). Never the less if you want to use .html file you can include it from .php script. Sense? You can just click on .html file to see the html formatting in browser (If you want to see formatting of page).

Last edited by webhope; 05-25-2010 at 05:20 AM.
 
Old 05-26-2010, 12:49 PM   #10
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
[Solved] Needed to add AddType to php.conf

Quote:
Originally Posted by webhope View Post
I just wonder why you use .html extension. I am used to use .php for php code, and I am not sure if php can run in .html file (be parsed). Never the less if you want to use .html file you can include it from .php script. Sense? You can just click on .html file to see the html formatting in browser (If you want to see formatting of page).
Using a file type of html makes coding simpler. I fixed it by this added to php.conf:
Code:
AddType application/x-httpd-php .php .html
Thanks for your time.
 
Old 05-26-2010, 01:19 PM   #11
diondeville
LQ Newbie
 
Registered: Mar 2010
Distribution: Kubuntu 11.10
Posts: 18

Rep: Reputation: 0
Have you tried saving your html file as .shtml and saving the php component as a .php file then using an SSI to include the .php into the .shtml?

Editing php.conf to get php to run in html files doesn't work on all servers; but php will usually run in an shtml file as an SSI.
 
Old 05-26-2010, 02:47 PM   #12
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by MrUmunhum View Post
Using a file type of html makes coding simpler. I fixed it by this added to php.conf:
Code:
AddType application/x-httpd-php .php .html
Thanks for your time.
Fine, but how on earth does it make coding simpler?

Whether the extension is html or php, the file contents should be identical.
 
Old 05-27-2010, 01:38 PM   #13
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by MTK358 View Post
Fine, but how on earth does it make coding simpler?

Whether the extension is html or php, the file contents should be identical.
I use Seamonkey ( Mozilla ) Composer to build the page. Unfortunately he does not support PHP code. I just wanted to LastModified date included. Much simpler with PHP.
 
Old 05-27-2010, 01:50 PM   #14
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
I too use the .html extension like you've showed, should be no probs there...

Have done as graemef said:
Quote:
Originally Posted by graemef View Post
Once you have apache set up correctly you need to access the page through apache. So don't try to view the page directly in your web browser but access through a proper URL which will make the web service (apache) serve up the page after having processed the php.
Can you view pages with the .php extension?

After installing server etc I always drop in a test page similar to the following:
Code:
<?php
phpinfo();
?>
I do name 'phpinfo.php', just for testing... it's also comes in handy at times...
 
Old 05-27-2010, 02:09 PM   #15
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by MrUmunhum View Post
I use Seamonkey ( Mozilla ) Composer to build the page. Unfortunately he does not support PHP code. I just wanted to LastModified date included. Much simpler with PHP.
OK.

I assumed you wrote the code by hand
 
  


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
PHP include upsets rendering of HTML page. rblampain Programming 6 01-19-2013 04:50 AM
display external html list item in new page using php? esteeven Programming 1 08-19-2010 02:06 AM
How do I output information from a PHP page to an HTML page? SentralOrigin Programming 3 01-10-2009 01:54 AM
php function to open an html page prabhatsoni Linux - Software 2 06-13-2005 11:32 PM
Creating a simple html page from php? lucastic Linux - General 4 11-05-2003 08:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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