2

I'm using Apache 2.2 on windows 7 to play a little with php5 code (locally via http://localhost/). The php is installed as apache 2.2 module.
Problem is, that php code works great (for example, <?php phpinfo(); ?> in index.php file),
and html code also works (<html><body>Hi!</body></html> in index.html), but
php script in html doesn't work (<html><body><?php phpinfo(); ?></body></html> in index.html).

What am I missing in the cofiguration file for running php script in html pages, locally?

3 Answers 3

3

Add this to your apache configuration:

AddHandler application/x-httpd-php .html
Sign up to request clarification or add additional context in comments.

Comments

0

You need to name files that have php code in them as .php otherwise apache won't parse the code.

For example:

<html><body><?php phpinfo(); ?></body></html>

Needs to be named

index.php

You do not need to name the files .html just because it's html in the file, but if there are php code you have to name the file .php.

Comments

-1

If you're putting php code in it, you have to call it index.php, not index.html.

2 Comments

not necessarily. You can tell your web server to process files with a .html extension as PHP files. See @Ken's answer for how to do this in Apache.
It depends on your setup. I like a more granular approach than automatically treating all html files with whatever PHP handler you're using (mod_php, cgi, etc.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.