prompt to download php file


Configuring PHP to run on IIS is usually a relatively straight forward task, but as there are many steps when configuring your server it can be a real pain to back track your steps when something goes wrong. Being prompted to download a php file or having your browser window fill with PHP code rather than it being processed by your server are among the most common problems encountered when configuring PHP on IIS. In this article we'll look at some possible causes and resolutions.

1. Check, double check and triple check your PHP application mapping in IIS. The single biggest cause of being prompted to download a PHP file rather than it being processed by IIS is that the PHP application mapping is not set correctly. Make sure that the path to the PHP DLL or CGI executable is correct (also ensure there are no spaces), the PHP application mapping is set to use the .php extension, at least the GET, HEAD and POST verbs are enabled, and that the "script engine" and "check file exists" options are checked. If in doubt, have a look at this on installing PHP 5 on IIS in 5 simple steps which is complete with screen shots.

2. Check your PHP scripts for usage of short tags. Quite often PHP scripts will be written using the short style tag. This will be the very first line in your PHP script, and if they use this then you'll need to enable the short_open_tag directive in php.ini.

3. Check if the PHP scripts your trying to run are in a sub or virtual directory. Because IIS ScriptMaps can be configured to run at global, site, directory and virtual directory level it is possible that not all sections of your site are capable of processing PHP scripts. If you can run a PHP script in one directory and it does not run when you move it to another directory, then you'll need to contact your host to establish where your PHP scripts should be located for correct operation.

4. Check the default_mimetype directive in php.ini. Make sure the mimetype for PHP is set to "text/html" in php.ini using the default_mimetype directive. It may also be worth inspecting your IIS configuration to ensure that a mimetype for PHP has not been set there.

5. Check your PHP scripts for usage of ASP style tags. I've never seen this myself, but if a PHP script where to use the ASP style tags then asp_tags directive in php.ini will need to be enabled.

Hopefully after inspecting your PHP environment for the points above you have managed to get it working. Feel free to comment or post a thread in the forums if you have any questions or comments.

Average rating
(4 votes)


Anonymous's picture

"Make sure that the path to

"Make sure that the path to the PHP DLL or CGI executable is correct"

Where? In what config file, MMC snap-in, or registry key? How is this done?

Brashquido's picture

IIS MMC snap-in

This is done in your IIS MMC snap-in, on the home directory tab. Click the configuration button and then scroll through the application mappings until your find your PHP mapping.

Dominic Ryan
6 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

index.php only downloads

If I enter 'wwwroot/test/index.php' in my browser, everything works OK, but 'wwwroot/test/' doesn't (index.php is downloaded).

And yes, I've added index.php in the default documents window -- even before index.htm and index.html.

Very strange. Any idea would be highly appreciated.