IIS, Phython

Enable Phython 2.7 on Windows IIS


The IIS configuration dialogues will differ between IIS versions.  This post used IIS 6 on Windows Server 2003.


 

1. Download and Install Python from the Official website

https://www.python.org/downloads/

Ensure the correct MSI installer file, 32-bit or 64-bit, is downloaded based on your current Windows operating system.  Make note of the installation location.  You will need this information later in the IIS configuration.


2. Define New IIS Application Extension

Python will be enabled on the Default Web Site.

Start the Internet Information Services (IIS) Manager using
Control Panel >> Administrative Tools >> Internet Information Services Manager.

CP_Admin_IIS_manager

On the Internet Information Services Manager window above , click  Web Sites on the left pane.  On the right pane, right-click the Default Web Site to display the pop-up menu as shown below.

IIS_manager1

Select Properties from the above pop-up menu.  The Default Web Site Properties window is displayed below.  Click on the Home Directory tab.

IIS_manager2

Click on the above Configuration button.  The Application Configuration window below is displayed.

IIS_manager3

Click on the above Add button.  The below blank Add/Edit Application Extension Mapping window is displayed.

IIS_manager4a

Find the installation location of the Python executable module by using the Browse button.

The entries used for my installation are as follows –

  • Executable: C:\Python27\phython.exe -u “%s” “%s”
  • Extension: *.py (to designate a python script)
  • Limit to: GET,HEAD,POST
  • Check mark the Script engine and Verify that the file exists check boxes.

The below window represents the completed application extension mapping.

IIS_manager4b

Click OK to complete adding Application Extension Mapping.

Click OK to the Application Configuration window.

Click OK to the Default Web Site Properties window.


3. Define New IIS Web Service Extension

On the IIS Manager, click Web Service Extensions on the left pane.

IIS_manager5

Click on the Tasks link, Add a new Web service extension…

The New Web Service Extension window below is displayed.

IIS_manager6

Enter the following information –

  • Extension name: Python
  • Set extension status to Allowed: Click the check box
  • Click the Add button to provide Required files information

The Add file window below is displayed.

IIS_manager7

Using the Browse button, find the location of the Python executable module.

Click OK for all windows to complete the new Web Service Extension.  Below is a snippet of all windows used followed by the final entry.

IIS_manager8
IIS_manager9

Restart IIS using iisreset from the command prompt window below.

IIS_restart

Congratulations!  Python is now installed and configured on IIS.


4. Validate Python on IIS

To test Python on IIS, save the below test script to your IIS web directory, typically, C:\Inetpub\wwwroot, as test.py.

#!/usr/bin/python

# Python test script
# test.py


# Browser output always starts with content-type statement followed by a blank line
print "Content-type: text/html"
print

# Browser HTML
print "<html>"
print "<head>"
print "<title>Phyton-Test</title>"
print "</head>"
print "<body>"
print "<hr>"
print "<h1>Python</h1>"
print "<h3>Howdy Y'all...</h3>"
print "<hr>"
print "</body>"
print "</html>"

On your browser address bar, enter  http://localhost/test.py 
 Note: This address will vary based on the location of test.py 

You should see a similar page as shown below.

Python_Test_Browser

Enjoy using Python scripts on IIS!

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image

This site uses Akismet to reduce spam. Learn how your comment data is processed.