Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Following an example of using php code inside html on the W3 page I have the following code inside my html code:

<!DOCTYPE html>

<p>First try with php:</p>

echo "My first PHP script!";


But only the text in the paragraph tags is shown (when opening the html page in a browser). Is there something wrong with the syntax? Do I need to configure something else in some setup?

Additional information: When I browse to a file test.php with the following content

<?php phpinfo() ?>

I get a whole bunch of configuration information; this shows me that apache is correctly configured for php. But why does the simple example above not work then?

share|improve this question

closed as off-topic by mdpc, Ward, faker, Falcon Momot, Tom O'Connor Aug 25 '13 at 22:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is a site dedicated to professionals; novice questions are off-topic. Please see the Help Center for more information on topicality. The best advice we can give you is to hire a professional to help you out." – mdpc, Ward, faker, Tom O'Connor
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 3 down vote accepted

You did not clarify, so my best guess would be that your file has a .html extension.

You may combine PHP and HTML in a single document, but you typically need to give it a .php extension in order for the code to be parsed. There is also the .phtml extension used by some, but I typically try to avoid using it for anything but Views (Google MVC if you really want to know).

Rename your index.html to index.php and that should take care of it. Unless this is done already, then please update us.

share|improve this answer
Yes thats it! Thaks a lot. – Alex Apr 6 '13 at 9:27
No prob and good luck! – David Houde Apr 6 '13 at 9:31
@Alex make sure you select this as your accepted answer – pauska Apr 6 '13 at 11:05

If you're using Apache as webserver you can write a .htaccess file to parse html files as php files. Here is an example

AddHandler application/x-httpd-php5 .html
share|improve this answer
Yes found this as well, but does not work. Maybe permissions on the file were wrong. – Alex Apr 6 '13 at 12:27
Are you sure about your php version? If it's not version 5 then try this: AddType application/x-httpd-php .html – n1kita Apr 6 '13 at 12:31

Just Create a .htaccess file in your root directory and then copy following line and then save.

AddHandler application/x-httpd-php5 .html .php .htm

Now code within any .html or .htm files will work as php so you dont need to change extension from .html to php

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.