0

I developed a Flask app. I am under the constraint to run this application on IIS Server. I have visited various websites on how to configure and prepared steps. At few places in configuring, I got confused with paths. I think I need to validate each step I have taken.

My flask app name is tourismmining and the contents of the directory is listed under

Application Structure

My application is structured in the below way.

tourismmining
|-> instance
|-> mining
|-> resources
|-> entry.py
|-> installation.txt
|-> License
|-> Procfile
|-> README.rst
|-> requirements.txt

The core application is in the directory mining and is structured in the following way

mining
|-> config
|-> db
|-> exceptions
|-> files
|-> forms
|-> logs
|-> models
|-> sink
|-> static
|-> templates
|-> __init__.py
|-> main.py
|-> utils.py

So, generally without using IIS server, just by flask local server, I used to run the below command

 cd tourismmining

 python -m mining.main  

and below is the output

enter image description here.

In touristmining, I have written an another file named entry.py, and it contains


      from mining import app

      if __name__ == '__main__':
          app.run(debug=True)

And I run the file entry.py using the below command

   cd tourismmining

   python entry.py 

enter image description here

I have show two ways to access my application. Now, I have visited many websites on how to configure IIS server, out of many, I picked two ways to configure the IIS Server. I wanted to know whether my approach is correct or not.

APPROACH #1

Step #1: Setup the site

In setuping the site phase, I have to move the application to inetpub/wwwroot. I am little confused.

Now, When I need to move the entire website, I have to copy the directory touristmining into C:\inetpub\wwwroot. isn't it ?


Step #2: Create a website

Creating a new website at the root of your application and below is snapshot picked from random website

enter image description here

As per the above screenshot,

Site name: tourism 
Physical Path: c:\inetpub\wwwroot\tourismmining   and the Click Ok.

Step #3: Add Module Mapping

enter image description here

Double click the handler mappings and towards to the right, I will find 'Add Module Mapping'. After opening add module mapping, below is the screen shot from a random website.

enter image description here

The parameters to my application will be as per the above screenshot is

  • Request Path: *
  • Module : FastCgiModule
  • Executable: C:\Python37\python.exe|C:\inetpub\wwwroot\touristmining\wfastcgi.py
  • Name: TouristMiningHandler

Before clicking Ok, I have to open Request Restrictions, and uncheck invoke handler, incase if it is checked and then click yes

Step #4: Go to the root server and click fastCGI settings

The list contains

  FullPath                   Arguments
-------------            ------------------

1.C:\Python37\python.exe   C:\Python37\Scripts\wfastcgi.py
2.C:\Python37\python.exe   c:\inetpub\wwwroot\touristmining\wfastcgi.py

Now, I double click the second link to launch Environment Variables Collection Editor and below is the snapshot is picked from the random site

enter image description here

Over here I have to set two paths

 1. PYTHONPATH
 2. WSGI_HANDLER

-> PYTHONPATH will be set to c:\inetpub\wwwroot\touristmining\
-> WSGI_HANDLER (Which path to set)
   
    is it mining.main.app
       or
    is it entry.app

Is there any other steps pending in Approach #1?

APPROACH #2

Step #1: Create a web.config file

Q) Do I need to create a web.config file ?

As per above application structure, the root directory of my application is tourismmining. Now, I copied to c:\inetpub\wwwroot. So, the directory contains c:\inetpub\wwwroot\tourismmining

If yes to above question, I have to create web.config file and then place it under c:\inetpub\wwwroot\tourismmining. Is it correct?

Then under tourismmining, the web.config contains

 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
 <system.webServer>
  <handlers>
   <remove name="Python27_via_FastCGI" />
   <remove name="Python34_via_FastCGI" />
   <add name="tourismmining"
      path="*"
      verb="*"
      modules="FastCgiModule"
      scriptProcessor="C:\Python37\python.exe|C:\inetpub\wwwroot\touristmining\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>

In the above xml under <appSettings>:

What should be the WSGI_HANDLER value ?

<add key="WSGI_HANDLER" value="myapp.app" />

Is it entry.app or mining.main.app

For PYTHONPATH, I have set the value to be C:\inetpub\wwwroot\touristmining

<add key="PYTHONPATH" value="C:\inetpub\wwwroot\touristmining\" />

Is this correct? Then restart the server and login to localhost:5000 in the browser. Is there any other steps pending?

Community
  • 1
  • 1
James K J
  • 605
  • 1
  • 8
  • 20
  • "I am under the constraint to run this application on IIS Server." Fight against that, as it became a dead end, https://stackoverflow.com/tags/wfastcgi/info – Lex Li Dec 31 '19 at 04:19
  • 1
    for PYTHONPATH value C:\inetpub\wwwroot\touristmining is correct and for WSGI_HANDLER set value entry.app. make sure you use python version after 3.6 . and do not forget to assign the iis_iusrs and iusr permission to the IIS python site and python folder. for more detail about how to configure python flask app in iis you could refer this [link](https://stackoverflow.com/a/59171787/11147346) – Jalpa Panchal Jan 01 '20 at 06:08

0 Answers0