Python on IIS: how?

Solution 1:

I just did this in 5 minutes.

  1. Insure you have IIS. run: %windir%\system32\OptionalFeatures.exe. Or, via pointy-clicky: Start...Control Panel...Programs and Features... (and then on the left hand side) Turn Windows Features on or Off. Make sure CGI is installed, under the IIS node.

    enter image description here

  2. Download Python for Windows, from python.org . I grabbed Python2.7. Make sure you get the x64 version if you have an x64 version of Windows.

  3. Unpack and install that python MSI. Choose the default, which puts python into c:\Python27

  4. Create a directory to hold your "development" python scripts. Eg, c:\dev\python

  5. Set the permissions on the files in the directory c:\dev\python to allow IIS to read and execute. Do this by running these two icacls.exe commands from the command line:

    cd \dev\python
    icacls . /grant "NT AUTHORITY\IUSR:(OI)(CI)(RX)"
    icacls . /grant "Builtin\IIS_IUSRS:(OI)(CI)(RX)"
    
  6. Open IIS manager. Run %windir%\system32\inetsrv\iis.msc, or do this via the control panel: Start...Control Panel...Administrative Tools...Internet Information Services (IIS) Manager. Create a new application. Specify the virtual path as /py and the physical path as c:\dev\python.

    enter image description here

    enter image description here

  7. Within that IIS application, add a script map for *.py, and map it to c:\python27\python.exe %s %s

    enter image description here

    enter image description here

    enter image description here

  8. create a "HelloWorld.py" file in c:\dev\python with this as the content:

    print('Content-Type: text/plain')
    print('')
    print('Hello, world!')
    
  9. invoke http://localhost/py/helloworld.py

Solution 2:

just make sure the path to the directory holding the cgi scripts doesn't have spaces or &.

i tried lots of things for many days and nothing worked then i changed the path and it worked

UPDATE: If it has spaces, put quotes around the path, but not the %s %s like this:

"C:\Program Files\Python36\python.exe" %s %s