Assume IIS is installed. My machine already had IIs 8.5.
DV : Adding some notes when using MS IIS Express 10
- Download web installer (Python 3.6.3).
- Run as Administrator.
- Select custom installation for all users.
- Choose install directory such that there are no white spaces in the path. Not sure if it needs to be done. Just being cautious.
- Check the box for "Add Python 3.6 to PATH".
- Open Windows Powershell as Adminstrator.
- Run:
pip install wfastcgi
- Run:
pip install flask
-
On the powershell, run:
wfastcgi-enable
It will produce configuration related output. Example:Applied configuration changes to section "system.webserver/fastcgi" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST". "c:\python36\python.exe|c:\python36\lib\site-packages\wfastcgi.py" can now be used as a FastCGI script processor.
DV: Make a note of the above output, the last line needs to be used in web.config later on. For IIS Express w/ default config and setup, run:
wfastcgi-enable "C:\Program Files (x86)\IIS Express\appcmd.exe" /apphostconfig:"C:\Users\davev\Documents\IISExpress\config\applicationhost.config"
-
Run IIS as administrator.
DV: For IIS Express simply open cmd, navigate to "C:\Program Files (x86)\IIS Express" and issue command "iisexpress.exe" Skip steps 3-6
-
Go to Connections and expand the tree.
-
Select "Sites".
-
Select "Add Website" under Actions panel on the right of the window.
-
A new window will pop up titled "Add Website". Fill in the necessary info: Site name, Directory containing the website content, IP address and port (I entered 5000). Since I want to simply run it on local host, IP address can be left as "All unassigned".
-
The Physical Path you specified in Add Website contains the following files (barebones):
**DV: For IIS Express by default this would be in your Documents folder, under "My Web Sites", example: "C:\Users\davev\Documents\My Web Sites\WebSite1". Create the "web.config" file in this directory
a. web.config: contains web configuration. It has the following content:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <remove name="Python27_via_FastCGI" /> <remove name="Python34_via_FastCGI" /> <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python36\python.exe|C:\Python36\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" /> </handlers> </system.webServer> <appSettings> <!-- Required settings --> <add key="WSGI_HANDLER" value="myapp.app" /> <add key="PYTHONPATH" value="C:\inetpub\wwwroot\stealth" /> </appSettings> </configuration>
b. myapp.py: contains Flask application:
from flask import Flask app = Flask(__name__) @app.route("/hello") def hello(): return "Hello Stealth!"
-
You might have to restart the Server and the website after configuration changes. Option will be under Actions on the right.
-
If you select the root node, you'll see a bunch of configuration features. We are interested in FastCGI Settings and Handler Mappings. a. Under FastCGI settings, I have the following:
Full Path | Arguments c:\python36\python.exe | c:\python36\lib\site-packages\wfastcgi.py c:\Program Files\PHP\php-cgi.exe
b. Under Handler Mappings, you'll see different names. Based on web.config, you'll see "Python FastCGI".
-
You can now enter "localhost:5000" into the browser.
DV: found this link useful: https://pypi.org/project/wfastcgi/
If i have a virtualenv, then i have to modif the python path on web.config file?