Python on IIS: how?
Solution 1:
I just did this in 5 minutes.
-
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. 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.
Unpack and install that python MSI. Choose the default, which puts python into
c:\Python27
Create a directory to hold your "development" python scripts. Eg,
c:\dev\python
-
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)"
-
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 asc:\dev\python
. -
Within that IIS application, add a script map for
*.py
, and map it toc:\python27\python.exe %s %s
-
create a "HelloWorld.py" file in
c:\dev\python
with this as the content:print('Content-Type: text/plain') print('') print('Hello, world!')
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