Overview
To host python on an IIS web server, you must install python and configure IIS on the machine.
In this case my organization doesn't allow internal servers any internet connectivity at all, so i had to figure out a way to get the dependent python packages via a manual download onto the server and install manually.
For some reason I had a hard time configuring the proxy for python, so I run Telerik Fiddler to funnel my traffic through the proxy anytime i need to install packages via pip.
I got my initial inspiration to try this from http://www.golden-orb.ltd.uk/ running-a-python-website- using-microsoft-iis/
The reason why I wanted to use Python for this project is it's really easy to prototype Object oriented libraries and expose a REST API via Flask. I was able to turn around a proof of concept whole project from inception to functioning site in a week (while juggling my other responsibilities).
Steps
1. Figure out which Packages you need
a. This step assumes you have Python installed locally. If not, download the Python installer and run it
b. From your local workstation, run Fiddler. This will funnel python web requests via the proxy
c. Open a command line as administrator
d. Use "pip" to install the packages you want.
e. Use the command "pip freeze > requirements.txt" to generate a list of installed packages. IF you can't use pip, write down the dependencies so you can find and download them manually
f. Use command `pip download -r requirements.txt -d offline_install` to download the packages you need. IF you can't use pip: go to PyPi, search for and download all the dependencies and packages you need
f. Use command `pip download -r requirements.txt -d offline_install` to download the packages you need. IF you can't use pip: go to PyPi, search for and download all the dependencies and packages you need
g. For a Flask application, you will likely need a minimum of
h. Your flask website will likely have a routing file in it where you instantiate the Flask app.
2. Install Python and the necessary packages on the server
a. Copy the Python installer to the server (I used version 3.6.5 for this example)
b. Install python
c. Copy the package files to the server
d. Run "pip" to install each local package
3. Configure IIS to use Python with FastCGI
a. Open IIS and choose "Add role Services"
b. Ensure CGI is selected
c. Right click on "sites" and choose "Add Web Site"
d. Add a site with whatever name you choose, e.g. ReportingSite.
e. Click on the web site you created and double click "Handler Mappings"
f. Pick "Add Module Mapping" from the right
g. At each prompt enter the following, replacing <MyPythonPath> with the directory where you installed python in step 2b.
h. When you continue, you will be prompted to create a FastCGI application. Click "Yes"
i. Not e that the wfastcgi package should have put the wfastcgi.py file in the folder you specified. Check that it exist just to be sure.
j. Click on your new website again and go to "Application settings" under ASP.Net and add:
4. Create a rule in the firewall to allow requests to go through
a. Open windows firewall
b. Add an Incoming rule to allow requests on the port you specified in step 3d
No comments:
Post a Comment