How to Deploy a Flask App to Linux (Apache and WSGI)
Why Stack Overflow recommends it
Stack Overflow users link it as a step-by-step guide for deploying Flask on Apache with mod_wsgi, and askers often cite it when their own deployment hits permission or 500 errors.
Recommended by 0 people across 0 different months, 2021 to 2023.
What it is
A screen-recorded tutorial by Luke Peters that walks through deploying a Flask app to an Ubuntu server running Apache2 with the mod_wsgi module. It covers uploading files, setting up a virtualenv, writing the WSGI and VirtualHost configs, enabling the site, and debugging errors.
What people said
Cites Arnaud Fontaine · 2021-10 · Stack Overflow · on “Error 500 while deploying my Flask app with mo_wsgi on Ubuntu VPS”
I am currently trying to deploy a very basic Flask app on my ubuntu VPS with mod_wsgi. I followed this youtube tutorial as precisely as I could : [this video] But i ended up with a 500 error. Here is a sample from the logs : mod_wsgi (pid=8283): Failed to exec Python script file '/var/www/flask-app/app.wsgi'. mod_wsgi (pid=8283): Exception occurred processing WSGI script '/var/www/flask-app/app.wsgi'. Traceback (most recent call last): File "/var/www/flask-app/app.wsgi", line 5, in <module> with open(activate_this) as file_: PermissionError: [Errno 13] Permission denied: '/root/.local/share/virtualenvs/flask-app-yYmzn1cG/bin/activate_this.py' The app.wsgi file : import sys sys.path.insert(0, '/va
Cites Nicojwn · 2022-01 · Stack Overflow · on “WSGI permission error when deploying flask app to apache2”
[Mon Jan 24 17:01:59.755348 2022] [wsgi:error] [pid 6837:tid 139969656289024] [remote xxx.xxx.xxx.xxx:xxxxx] mod_wsgi (pid=6837): Failed to exec Python script file '/var/www/FlaskDeliverN/app.wsgi'. [Mon Jan 24 17:01:59.755407 2022] [wsgi:error] [pid 6837:tid 139969656289024] [remote xxx.xxx.xxx.xxx:xxxxx] mod_wsgi (pid=6837): Exception occurred processing WSGI script '/var/www/FlaskDeliverN/app.wsgi'. [Mon Jan 24 17:01:59.760074 2022] [wsgi:error] [pid 6837:tid 139969656289024] [remote xxx.xxx.xxx.xxx:xxxxx] Traceback (most recent call last): [Mon Jan 24 17:01:59.760109 2022] [wsgi:error] [pid 6837:tid 139969656289024] [remote xxx.xxx.xxx.xxx:xxxxx] File "/var/www/FlaskDeliverN/app.wsgi", l
Cites lstuma · 2023-03 · Stack Overflow · on “Python/Flask web site for the www”
If you're serious about deploying your webapp to the vast realm of the internet, you will need to use a viable framework to do so. Something like apache should do the job. I won't go into detail as to how to deploy a webapp as there are many tutorials out there, but I'll provide some resources below: [LINK] [LINK] [LINK] [this video] Also remember to activate your SSL/TLS certificate (easy way to do that would be for example certbot) and enable HSTS.
Cites Stryker2k2 · 2023-10 · Stack Overflow · on “Running Flask with Flask_Login on Apache2 causes Webpage Login Issues”
I'm out of ideas. When I run my Flask Website locally, everything works fine. Two users can use my website using two different browsers at the same time and everything just... works. Flask's Flask_Login deals with all the session cookies and current_users perfectly. But, it all goes crazy when I push my build to the Apache2 production server. When an Administrator logs in, it seems that everyone else is considered to be that Administrator. It is almost as if there is a duplication of cookies... or confusion about who the 'current_user' is. My server is using Apache2 and I have mod-wsgi-py3 installed. I followed this tutorial ( [this video] ) to push my Flask App to my Production Apache server. He