ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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><FilesMatch \.php$><br>  SetHandler application/x-httpd-php<br></FilesMatch></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>
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.
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.
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.
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?
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
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.
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.
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.