LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   php not running in html page (https://www.linuxquestions.org/questions/programming-9/php-not-running-in-html-page-809533/)

MrUmunhum 05-22-2010 04:28 PM

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.

Fingers of Fudge 05-22-2010 06:11 PM

Did you enable/set up php in apache?

RockDoctor 05-22-2010 06:29 PM

Code:

sudo yum install php
or
Code:

sudo apt-get install php
depending on your distro

graemef 05-22-2010 06:56 PM

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.

MTK358 05-22-2010 07:23 PM

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.

MrUmunhum 05-23-2010 01:16 PM

Quote:

Originally Posted by RockDoctor (Post 3977968)
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


MrUmunhum 05-23-2010 01:19 PM

Quote:

Originally Posted by Fingers of Fudge (Post 3977959)
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

vikas027 05-25-2010 03:51 AM

I was also facing a similar problem, see this.

webhope 05-25-2010 04:29 AM

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).

MrUmunhum 05-26-2010 12:49 PM

[Solved] Needed to add AddType to php.conf
 
Quote:

Originally Posted by webhope (Post 3980379)
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.

diondeville 05-26-2010 01:19 PM

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.

MTK358 05-26-2010 02:47 PM

Quote:

Originally Posted by MrUmunhum (Post 3982002)
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.

MrUmunhum 05-27-2010 01:38 PM

Quote:

Originally Posted by MTK358 (Post 3982116)
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.

brazilnut 05-27-2010 01:50 PM

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 (Post 3977982)
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...

MTK358 05-27-2010 02:09 PM

Quote:

Originally Posted by MrUmunhum (Post 3983240)
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 :)


All times are GMT -5. The time now is 09:24 PM.