DEV Community

Flask on Windows using Apache

William Sousa on August 02, 2020

Flask is a Python based micro-framework, which can be used to create dynamic websites, APIs, and many other applications. Despite all Linux cloud ...
Collapse
 
shreyanse081 profile image
Shreyans Jain • • Edited

Hi William, thank you for the amazing article. I was facing a small issue with VHost.conf file in tag.
Error:
AH01630: client denied by server configuration: C:/git/wsgi_scripts/yourapp.wsgi
Solution:
It worked for me with <Directory C:/git> instead of <Directory C:/git/yourapp>

Also deploying it with flask there was an issue with few other packages like Pandas and Scikit-Learn where the flask was hanging.
So to solve this I added one line WSGIApplicationGroup %{GLOBAL} in httpd.conf under - Reference

LoadFile "c:/program files/python37/python37.dll"
LoadModule wsgi_module "C:/Users/prod_deploy/AppData/Roaming/Python/Python37/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/program files/python37"
WSGIApplicationGroup %{GLOBAL}
Enter fullscreen mode Exit fullscreen mode

I also hope this helps others.

Collapse
 
willmvs profile image
William Sousa •

Thank you for the feedback and these other hints Shreyans!

Collapse
 
fabiolus profile image
fabiolus •

Thanks Shreyans - I encountered an issue when just importing spacy in the flask app
adding WSGIApplicationGroup %{GLOBAL} fixed it

Also regarding the Error:
AH01630: client denied by server configuration:

Changing the directive from

to

worked for me.

Collapse
 
ganeshkp11 profile image
Ganesh • • Edited

Hi William,

I followed steps as you said..I am trying to diploy dash application. When i run server, webpage keeps running without any results. Any specific things needs to be considered?? Please help me on this.

Regards
Ganesh

Collapse
 
aitahmed99 profile image
AitAhmed99 •

Hello Ganesh, I am trying to deloy a dash application as well under wampserver stack ( it's a Web server stack package including apache). the app is not rendered, I still get "it works!" in the web page when I test it. I would like your guidance if you've managed to succesfully deploy it. Thanks.

Collapse
 
willmvs profile image
William Sousa •

Sorry Ganesh, I didn't get notified of your post. I'm not sure about "dash application", but I recommend that you check the Apache logs on C:\Apache24\logs , to see if any error was recorded.

Collapse
 
appleonly707 profile image
appleonly •

Hi William, Thanks for the article. I am just having trouble booting up apache after adding the Config lines in httpd.conf file. Getting this in my error logs -

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Already checked that Encodings module is present and python is correctly installed.

Can you please help?

Collapse
 
quangyendn profile image
yennq • • Edited

Thanks for the post.
Apache is robust but it doesn't support well socket communication on Windows.

Collapse
 
willmvs profile image
William Sousa •

Thank you for the feedback. I still need to learn more about Apache, are you saying it might face issues once it needs to handle multiple connections?

Collapse
 
chandersheel profile image
chandersheel • • Edited

Hi william,
Thanks for the great article. Although, I am stuck at a problem while executing command at step-4 i.e. "mod_wsgi-express module-config" in command prompt. It is throwing "failed to create process" error. I have also searched many articles on the internet but did not find the solution. Kindly guide me through this error, if you know this.
Thanks

Collapse
 
aitahmed99 profile image
AitAhmed99 •

Thank you William for this detailed article. I am a complete newbie trying to deploy a dash application (mainly a Flask app) in windows environment. I have apache server already set up under wampserver (in my understanding it's a Web server stack package including apache ). However, I followed the steps as if apache is not there yet. Now, after completion, the app test (localhost test) is still returning "it works!" instead of the actual app.
I am stuck at this point, I would appreciate any comment of suggestion.
PS1: the app was tested in localhost and it works perfectly
PS2: my team uses wampserver for integrating other tools and apps, so this choice is kinda out of my hand. However, I am open to any other suggestions to rectify this.

Collapse
 
deepank2596 profile image
deepank2596 •

Hi William,

Can u plz tell how to update hosts file to test the app locally.

Collapse
 
willmvs profile image
William Sousa •

Hi deepank2596,
On Windows the hosts file is usually on C:\Windows\System32\drivers\etc . I believe it's a good idea to make a backup in case you make a mistake, and depending on your settings you might need admin access to edit the file. Once you edit it, you can add entries like this one:
127.0.0.1 willtest.com

It points to a fake address that I can type on my browser to simulate going to a real address. Besides that you can always use localhost on your browser to test the app locally.

Collapse
 
stonawski profile image
stonawski •

Hi William,

after starting Apache, localhost shows just Forbidden site with error 403. Any advice?

Collapse
 
aokiahishatsu profile image
xeno • • Edited

I also get HTTP 403 Forbidden

EDIT: Change the <Directory C:/git/yourapp> to <Directory C:/git> as described in the comment above.

Collapse
 
fabiolus profile image
fabiolus •

Thanks for sharing this William!