LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-08-2013, 03:13 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
PHP won't work in HTML file.


Hi,

I recently upgraded Ubuntu from 11.10 to 13.04. Programs that I ran before had many instances where I had PHP5 code embedded in an HTML program. They worked! Since the upgrade I can't get PHP5 to work in my html files. The following is a little test I ran. It does not work. Any comments out there. I figure I am doing something dumb again.

Thanks, R


Code:
<!DOCTYPE html>

<html>
	<head>

		<!-- myTest.html ... Test program as PHP cannot be accessed inside .html file ... 2 Oct 2013 -->
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<title>My Test - PHP inside HTML</title>

	</head>


	<body>
		<p> <b>This is my code to see if PHP will work inside an html file.</b><br>
		As you can see it does not work.</p>
		

		<!-- PHP code should produce [Hello there people.] in line 24. </b> HERE. -->

		<p> ======================== </p>

	<?php

		echo "Hello there people.";

	?>
		<p> ======================== </p>

		<p> I put the file <b>.htaccess</b> in the directory containing this .html file<br> It says:  ... <b>SetHandler application/x-httpd-php5 .html</b> ... 				and 	does not work!</p>
		<p> In the <b>/etc/apache2.conf</b> file I put the following at the end of the file: </p>
		<p> <b>&ltFilesMatch \.php$&gt<br>&nbsp&nbspSetHandler application/x-httpd-php<br>&lt/FilesMatch&gt</b><br></p>
		<p> I found the information above at various internet sites. Nothing seems to work here.

		<p> <b>NOTE:</b> I don't know whether it makes a difference or not but to access <b>myTest.html</b> program here I have a softlink in /var/www that 						  points to the directory containing this file in my /home/user/ folder.


	</body>
</html>
 
Old 10-08-2013, 05:18 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,721

Rep: Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914
What happens if you rename your mytest.html to mytest.php.
 
Old 10-08-2013, 05:39 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,268
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
That sounds like an Apache directive was changed, or maybe you went from PHP 4 to PHP 5?

You should check your httpd.conf (not sure where that is in Ubuntu) and add the handler then restart apache, or per-directory you can probably add this to a .htaccess file (if enabled):

Code:
AddHandler application/x-httpd-php5 .html
To change it globally add or enable a line like this in your /etc/.../httpd.conf:

Code:
AddType application/x-httpd-php5 .html
NOTE: The above are examples, Ubuntu my have slightly different names or mime type defs.

Last edited by astrogeek; 10-08-2013 at 05:43 PM.
 
Old 10-09-2013, 01:25 PM   #4
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Thank you, michaelk and astrogeek for your replies.

michaelk: Change name to myTest.php - all is fine, it works.

astrogeek: Added AddType application/x-httpd-php5 .html to httpd.conf file - no change, it does not work
 
Old 10-09-2013, 01:49 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,721

Rep: Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914
At least php works.
Did you restart appache after modifying the httpd.conf file?
 
Old 10-09-2013, 02:23 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,268
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Just to be very explicit, the location of the line in the httpd.conf file matters, and there may already be one.

So search the file for an existing AddType ... .php line

Code:
AddType application/x-httpd-php5 .php
Add append .html to it, something like this...

Code:
AddType application/x-httpd-php5 .php .html
You must then restart Apache - not sure how that is done in ubuntu, but probably something with apachectl, or through a service manager GUI.
 
Old 10-09-2013, 07:01 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Stop and think of it from Apache's (I'm a stupid-computer ...) point-of-view.

"I've been asked to deliver a meaningful response for http://www.foobar.com/bletch.html."

So, first of all, Apache tries to equate www.foobar.com to some <VirtualHost> definition that it has been made aware of.

Then, if this succeeds, it attempts to resolve this to a <Directory> (in this case, there is none).

Now, it looks at the suffix, in this case .html, to decide what to do. (If it finds no so-called Handler for this prefix, it will resort to its default action: it will find the file and deliver its content.)

Wel-l-l-l ... "there is none." Therefore, Apache simply delivers the content of the file, verbatim. It doesn't hand it to the PHP interpreter.

If it had found a "handler," it would have submitted the file to "one interpreter or another" and delivered the output to the user.
 
Old 10-13-2013, 02:01 PM   #8
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Angry

Hi, Things are getting worse not better!!!

Here is my /etc/apache2/httpd.conf file:

Code:
ServerName localhost
AddType application/x-httpd-php5 .php .html
When I now run my program firefox opens the file from file:///tmp/healthConnect.html. Somehow firefox or firebug put it there??? This, of course, messes up everything as the real location ~/DB-Web/health, in this case, contains all the .php and .html files which contain references to the .css and .js files . Since my .css and .js files are no longer accessible nothing works.

Should I just re-install firefox and firebug??

Totally frustrated and getting nowhere,

R
 
Old 10-13-2013, 02:08 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,268
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Quote:
Originally Posted by pizzipie View Post
Hi, Things are getting worse not better!!!

Here is my /etc/apache2/httpd.conf file:

Code:
ServerName localhost
AddType application/x-httpd-php5 .php .html
When I now run my program firefox opens the file from file:///tmp/healthConnect.html. Somehow firefox or firebug put it there??? This, of course, messes up everything as the real location ~/DB-Web/health, in this case, contains all the .php and .html files which contain references to the .css and .js files . Since my .css and .js files are no longer accessible nothing works.

Should I just re-install firefox and firebug??

Totally frustrated and getting nowhere,

R
You are opening it as a file, not via http request. Apache is not even serving it at that point.

You must request it as an http request - same as you were doing when you renamed it to .php and said that it worked.

Is your web server even running? Have you configured any virtual hosts?

Assuming that you have not configured any virtual hosts that would come into play, what do you get when you try to open http://localhost in your browser?

Reinstalling is nonsense - why would you do that?

Last edited by astrogeek; 10-13-2013 at 02:10 PM.
 
Old 10-13-2013, 06:51 PM   #10
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
I have not installed any virtual hosts. I tried one time and was not successful. That is why I have a softlink in /var/www which points to my directory with my programs in them ~/DB-Web.

1. Assuming that you have not configured any virtual hosts that would come into play, what do you get when you try to open http://localhost in your browser?

2. Reinstalling is nonsense - why would you do that?


1. I enter this ... localhost/DB-Web/health/healthFrontEnd.php. One of the selections in this file is as follows:

Code:
<button type="button" class='hov'  name="connect" id="connect" onclick="window.location.href='healthConnect.html'">See Health Logs</button>
When I click on the button the browser does this: files:///healthConnect.html. Which led to my previous post. I didn't do it!!!

2. Because I don't know what I'm doing in a lot of this!!!

Last edited by pizzipie; 10-13-2013 at 06:55 PM. Reason: added ans. to question
 
Old 10-14-2013, 12:16 PM   #11
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Well guess what?

I removed AddType application/x-httpd-php5 .php .html from the /etc/apache2/httpd.conf file and am now back to square one. That is my programs work again. Except the PHP problem.

Any advice from here??

R
 
Old 10-14-2013, 04:22 PM   #12
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,268
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Quote:
Originally Posted by pizzipie View Post
Well guess what?

I removed AddType application/x-httpd-php5 .php .html from the /etc/apache2/httpd.conf file and am now back to square one. That is my programs work again. Except the PHP problem.

Any advice from here??

R
Hmmm... then I suspect that Apache may have failed to start, maybe due to a bad httpd.conf.

I might ask you to post your entire httpd.conf as a next starting point.

It would also be a good idea to check the httpd/error_log to see why it was not starting with the AddType line.

Your problem is really a simple one of configuring Apache correctly, and the AddType directive is key, but I am not an Ubuntu user so I stumble over just what the Ubuntu defaults and paths are.

So, I'll bump this back to the top and invite any Ubuntu users with default Apache config experience to chime in here.

The question in a nutshell is: How to add PHP handling for .html files in Apache with Ubuntu 13.04.

As time permits I'll do my own searches to see if we can get to quick solution for you.
 
Old 10-14-2013, 07:03 PM   #13
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Hmmm... then I suspect that Apache may have failed to start, maybe due to a bad httpd.conf.

I might ask you to post your entire httpd.conf as a next starting point.


This was the entire file.

Code:
ServerName localhost
AddType application/x-httpd-php5 .php .html
Apache did start. When I took AddType application/x-httpd-php5 .php .html out of the httpd.conf file my programs started to work again. Somehow that directive is screwing things up.

It would also be a good idea to check the httpd/error_log to see why it was not starting with the AddType line.

I just looked at some of the errors that show up in the apache2/error.log and will try to make sense of them.

Meanwhile, thanks a lot for having the patience to hang in here with me.

R
 
Old 10-14-2013, 07:16 PM   #14
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,268
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Ah! Then I don't think that will work. The AddType directives must be inside a something like an <IfModule mime module> and maybe a directory element.

Do you know the history of that httpd.conf file - where it came from, who created it? I don't think that would be the default Ubuntu httpd.conf file (although I really don't know).

That makes me wonder if your upgrade to 13.04 was complete or not.

I am still hoping an Ubuntu user will hop in here, but I'll look a little deeper into that as time permits.
 
Old 10-14-2013, 07:21 PM   #15
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,268
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Let's try a quick work around...

Create a file named .htaccess in the apache root directory (or edit one if it exists). The apache root is probably something like /var/www/html/ - or whereever you have the symlink to your target page would do.

Try each of these variations in that file:

Code:
AddHandler application/x-httpd-php5 .php .html

AddHandler application/x-httpd-php .php .html
You should not have to restart Apache for that to take effect, just refresh the page in firefox. If one does not work, comment it out and try the other.

*** AddHandler must go into .htaccess, NOT AddType - sorry

Last edited by astrogeek; 10-14-2013 at 07:28 PM. Reason: changed AddType to AddHandler
 
  


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
how to add a php file in /var/www/html folder mukeshk.nist Linux - Software 2 01-24-2010 11:20 PM
[SOLVED] Using php to call am html file jus71n742 Programming 8 10-21-2009 11:27 PM
PHP won't recognize my Configuration File (php.ini) path kriezo Programming 4 02-14-2008 02:31 AM
PHP: Read html file, diplay result kenneho Programming 10 02-17-2006 08:33 AM
php in an .html file does not work NW Otter Linux - Software 4 09-23-2003 04:10 PM

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

All times are GMT -5. The time now is 04:56 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