Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to include php in html on IIS7?

It seems to be possible to do so in Apache,

include php script inside HTML

But can I make my IIS 7 parse html files for php? Currently my html files allow asp includes like it would be splendid if I could just do that with a php file.

My server runs .php files as you would expect.

What I've tried is adding a Handler Mapping in IIS with the same values as the *.php mapping that was created with my IIS/PHP install, only switched for *.html

This didn't work, then I added a handler in my web.config file

<add name="PHP_via_FastCGI" path="*.html" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" resourceType="Either" requireAccess="Script" />

like that, and that didn't change anything.

There are no errors when I run an html file with php code in it, the code just simply does not run.

Let's assume that I cannot just simply change my index.html to an index.php.

like image 778
Lactose Avatar asked Mar 05 '12 22:03

Lactose


People also ask

Can you include PHP in HTML file?

If you want to run your HTML files as PHP, you can tell the server to run your . html files as PHP files, but it's a much better idea to put your mixed PHP and HTML code into a file with the . php extension.

Can we host PHP Web site on IIS?

IIS only runs on Windows, but keep in mind that running PHP on IIS is not the same as running PHP on Windows. There are options to run PHP on Windows like XAMPP or WampServer. However, these two options make some additional choices for you. They run Apache as a web server and use MySQL or MariaDB as a database server.

Where do I put PHP script in HTML?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.

Can PHP run on Microsoft Windows IIS?

The fastest and easiest way to install PHP on Internet Information Services (IIS) is by using the Microsoft® Web Platform Installer (Web PI). Web PI completely automates setting up IIS, FastCGI, and the latest version of PHP from the php.net Web site.


1 Answers

I had to get this working for a site migrated from apache to IIS that used a mixture of .php and .html for it's scripts. I have this (cropped useless stuff) in my web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="PHP53_via_FastCGI_HTML" path="*.html" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" resourceType="File" requireAccess="Script" />
        </handlers>
    </system.webServer>
</configuration>

Have you got it in the right section? I hate that most web.config examples I see don't actually tell you want section they should be in </rant>

like image 58
Richard Benson Avatar answered Sep 28 '22 10:09

Richard Benson