It took me about 3 days to figure out how to deploy a flask application on a windows server using Apache so I thought I should write a tutorial to help someone else and for my own reference in the feature. Please let me know if you have any questions because I know this is not an easy task to understand. If you have any questions feel free to ask.

  1. Install python for all users. Note install it for all users.
  2. Set python as the environmental variable like soEnvironmental Variables

3. Open the comandline and Run pip install virtualenv like so

            C:\>pip install virtualenv

4. Create a directory called myapp

            C:\>mkdir myapp

5. Run

            C:\>cd myapp

6. Run virtualenv Flask

          C:\myapp>virtualenv Flask

7. Run

           i. C:\myapp>cd  /Flask/Scripts

8. Run

         C:\myapp\Flask\Scripts>pip install flask

Now you have installed your flask infrastructure

We are going to create a file in our root directory called using any text editor like notpad or notepad++

9. Past the content below into it

from flask import Flask
 app = Flask(__name__)
 def hello():
     return "Hello from FastCGI via IIS!"
 if __name__ == "__main__":

It will look like this

index one

10. Now go to the command prompt and run


11. Run

      i. (flask) C:\myapp\Flask\Scripts>cd ..

      ii. (flask) C:\myapp\Flask>cd ..

iii. (flask) C:\myapp>cd app

       iii. And Run (flask) C:\myapp\app>python

It will look like this

command line

12. Now open your browser and type in  http://localhost:5000

localhost 5000

We have now setup flask to run on the development server.


Now we have to configure apache to run python and serve it to the world.

13. Go to and download wamp or apache standaloan from here or

14. Extract the files and copy Apache24 to  C:\Apache24

15. Navigate to C:\Apache24\bin and run or click on httpd.exe to start apache

Start apache

16. Go to your browser and type in http://localhost


We have now setup a development server for apache.

Now lets configure the system to run python from apache. But before we start, go here and download mod_wsgi. Without it you cannot run python flask on windows.

Note: if you are using 64bit system download 64bit Apache,64bit python and use the 64bit  and if you are using a 32bit system use everything that is 32bit.

Read more on this from here

17. Look for the right file and copy it to C:\Apache24\modules and past it.

18. Navigate to C:\Apache24\conf and open httpd.conf in a text editor

19.Add LoadModule wsgi_module modules/ to the modules

20. Remove the # from LoadModule cgi_module modules/

21. Add +ExecCGI to your Options it should look like this

<Directory "c:/Apache24/htdocs">
   Options Indexes FollowSymLinks +ExecCGI
   AllowOverride None
   Require all granted

22. Locate the tag <IfModule mime_module> and inside it, add

 AddHandler cgi-script .cgi
 AddHandler cgi-script .py

23. Locate this tag <IfModule dir_module> and inside it add and it will look like this

<IfModule dir_module>
 DirectoryIndex index.php index.php3 index.html index.htm index.cgi

24. Now create another file called inside the root directory here C:\myapp>

25. Add this code to it

import cgitb
print("Content-Type: text/html;charset=utf-8")
print("Hello World!")

26. Restart apache

27. Go to your browser and type http://localhost/ It will say Hello World meaning you are now running python scripts on apache server

Hello World

28. Now find out how to use virtual host in apache if you have no idea. Add the code below to the virtual host file

<VirtualHost *:80>
 ServerName localhost
 WSGIScriptAlias / "C:/myapp/app/web.wsgi"
 DocumentRoot C:/myapp/app
 <Directory "C:/myapp/app/">
 Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
 AllowOverride All
 Require local

29. Create a file called web.wsgi in the root of your application like so

import sys
from app import app as application


30. Now create another file in the root of your application called and add the following code.

from flask import Flask
app = Flask(__name__)

def hello():
 return "Hello from FastCGI via IIS!"
if __name__ == "__main__":

31. Restart appache

32. Navigate to http://localhost and you will see this

apache server is running python

Useful links

Configure server to compile mod_wsgi –

Download file –

Download files –



If you enjoyed this article, share or tell a friend and be on the lookout for more from

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *