Question

Can't embed PHP code to the HTML file

Asked by: Jagadguru

Hello All,
     I have set up LAMP on my notebook. The versions of the packages are as follows
   -Ubuntu 8.04
   -Apache2
   -MySQL, Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)
   -PHP-5
   
  With this set up I am unable to run html files with php code embedded in it. The example html file (example.html) looks like this

  <head>
<title>Greeting Program in PHP</title>
</head>
<body bgcolor=white>
Programming courses always start with a program that says<BR>
<font color=red size=5>
<?php
print ("Hello World.") ;
?>
</font><P>
On this course, the message is embedded in a web page.<HR>
Demonstration page for PHP training - Well House Consultants Ltd
<a href=http://www.wellho.net/resources/H101.html>PHP Intro</a>
</body>

To be precise, only the "Hello World" does not get displayed on the browser. Based on fix provided by some forums, I did the following

1. I added the .html extension  to the /etc/apache2/mods-available/php5.conf file

 <IfModule mod_php5.c>
  AddType application/x-httpd-php .html .php .phtml .php3
  AddType application/x-httpd-php-source .phps
 
</IfModule>

2. I created a file called .htaccess under /var/www/ directory and put

AddType application/x-httpd-php .html .php

line to that.

Both these fixes which worked for some people didn't worked for me. I am not sure what's going wrong here? Can anyone please let me know the fix?


Thanks,

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-05 at 14:29:45ID24787108
Tags

Apache

,

PHP

,

HTML

Topics

PHP Installation

,

Hypertext Markup Language (HTML)

,

Apache Web Server

Participating Experts
4
Points
250
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. embed .htaccess ?
    any of you clever chappies out there know if its possible to embed the user inputs (username & password) of a .htaccess password protected directory into an html page ?
  2. Embed .htaccess pop-up box in webpage with PHP??
    Hi, My first question here at experts exchange. Anyways, here goes. I have heard that you can somehow embed into a webpage the username and password box that appears when you try and enter a site protected with .htaccess. I would use some other password protection script, ...
  3. php and .htaccess
    Hi, I want to implement a very basic password protected section of a site. A folder is to have a .htaccess file with users and associated passwords (simple). Is there a simple way in php to allow a user to edit their own password by providing their current user name and pass...
  4. Installing Apache, Php, mysql on ubuntu server hosted b…
    Hey guys, I am new to the linux distribution so if anyone could kinnda guide me through the process would be great.. Correct me if I am wrong do I need to install apache server on ubuntu server or does ubuntu server comes with pre install apache? I normally work on my own ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: christophermccannPosted on 2009-10-05 at 14:36:11ID: 25500031

Does nothing get rendered out or does it render out the <?php tags as well?

Did you restart apache after you made the update?

Your extension on the file should not be .html but .php

 

by: stehardy88Posted on 2009-10-05 at 14:37:43ID: 25500054

This page explains it (and setup): http://ahtim.com/audio-sound-over-remote-desktop-connection/

Note:Audio will be a bit lagging when open huge application such as iTunes.

 

by: JagadguruPosted on 2009-10-05 at 14:41:41ID: 25500083

stehardy88 I think you are replying to someone else's question.

 

by: christophermccannPosted on 2009-10-05 at 14:52:39ID: 25500177

@jagadru - did you note my points?

 

by: JagadguruPosted on 2009-10-05 at 14:57:15ID: 25500219

@christophermccann My friend Kailash is here who is really the one with the problem. He'll make a comment here shortly.

 

by: JagadguruPosted on 2009-10-05 at 16:17:25ID: 25500755

christophermccann, thanks for your response, Sorry for the delay.

>Does nothing get rendered out or does it render out the <?php tags as well?
  Only html contents are rendered, no php contents are rendered, not even <?php tags.

>Did you restart apache after you made the update?
  Yes, I did that every time I made changes to the apache2 sever files.

>Your extension on the file should not be .html but .php
   This is what I don't want. Well if you can give me some nice one column php web templates then I will just use a php file. However, I want HTML and CSS for the style and design of the website. If that purpose can be served alone by php files then I can go for that.

Thanks,
Kailash

 

by: christophermccannPosted on 2009-10-05 at 16:19:29ID: 25500768

PHP is exactly the same as an html file except you can run php inside it as well as html css. Change your extension to .php and it should hopefully sort your problem. You will not need to change anything inside the file such as html or css. They are kept exactly the same as if the extension was .html

 

by: JagadguruPosted on 2009-10-05 at 17:00:00ID: 25500982

I changed the file extension to php but the browser won't execute it, it asks me to save the file. But tha'ts happening to other php files too. This wasn't use to happen, I think screwed up the apache sever. I will have to reinstall it. I will get back with you after that.

Thanks,
Kailash  

 

by: CraybePosted on 2009-10-06 at 15:10:26ID: 25510459

The file definitely needs to be .php to execute php code.  If it asking to save the file it would suggest that Apache isn't running or you are trying to access the file locally not off the virtual server.  You have probably looked into this but just in case, for it to execute the code you need to access the file from the server not a local file.  I don't have experience with LAMP however I do use WAMP, you need to access the file using the ip address of the computer which will reference the root directory of the "server".  If you haven't already tried that give it a go.

 

by: yfastudPosted on 2009-10-06 at 19:43:42ID: 25511838

AddType application/x-httpd-php .html .php

the above line should be used for win, ie. wamp, and for *nix, try this line instead
AddType x-mapp-php5 .html .htm

and you should have no problem to embed php in html and the files still save with html extension as seen in my sites here

http://guides.jlbn.net/

 

by: JagadguruPosted on 2009-10-07 at 08:15:30ID: 25516420

Craybe and yfastud: You were both right. Combining these two solutions solved the problem. Thanks!

 

by: yfastudPosted on 2009-10-07 at 14:15:53ID: 25520187

points already assigned so just add my 2-cent thought here in case some other users might take a look at this solution ;)

I'm NOT completely agree w/ Craybe that "The file definitely needs to be .php to execute php code." and that's why I've provided the solution above as they are actually codes that I've been using for my pc's

to be exact, in my win7, I have this line:
AddType application/x-httpd-php .html .htm

and in my ubuntu, I have this line:
AddType x-mapp-php5 .html .htm

and most files, if not all, save as .html even they contain php script as seen on my sites here ;)
http://jlbn.net/

 

by: CraybePosted on 2009-10-07 at 14:42:05ID: 25520414

You are correct yfastud, but just because it is possible doesn't mean it is a good choice.  The above code is conditional on operating system which means it is not a universal solution.  This being the case there is a chance that an update to an OS or Browser may be released which will instantly invalidate your code.  It is always best to keep things as simple as possible, if the file contains php call it a php file.

I'm not saying you're wrong though and I have definitely appreciate learning something new.

 

by: JagadguruPosted on 2009-10-07 at 14:51:48ID: 25520486

I agree with yfastud, that the flle extension need not be .php and I also agree with Craybe that if the file contains php then extension should be .php but it depends. I would say that if php is embedded in HTML then file extension should be .html and if the html is embedded in php code then the file extension should be .php. Let me know if I am wrong

 

by: CraybePosted on 2009-10-07 at 15:44:44ID: 25520942

It is all a matter of personal taste :-)  

There is a short article at http://www.wellho.net/mouth/1355_-php-or-html-extension-Morally-Static-Pages.html that may help.

It makes a good point of the fact that when some people see .php they will see it as a dynamic page and they won't bookmark it as it may change.  They also think it may effect search engine hits, I know this is untrue as all my php websites use .php and they all show up fine in search engines.  But public perception is a good point so using html is not necessarily a bad idea.  Either way good luck with your project!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...