Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask deployment from heck
#1
Hi and hello. This is my first post. To summarize, I retired from 44 years as a C and dinosaur-language programmer in April of '20. My wife was using Excel to categorize our collection of LPs, CDs and DVDs. Hey, why not make a web app with a RESTful back-end (Flask) and modern (Svelte) front-end for her? Done. Had to learn Flask and Python and JavaScript and Svelte (although I did a little Angular on my last project). Everything worked in the development server, my WIN10 PC. Oh, and MySQL as the database. No comments about any of my choices would be appreciated. So, I stood up an Ubuntu 20.x PC for my Plex server and installed Apache, and all things Flask and MySQL. Running the Flask app from a terminal session on port 5000 works fine. Changed it to a different port and it still works. My wife can add/edit/display the media records in the database. As long as the Linux box doesn't go to sleep. When it does, it stops listening (duh). I put a SSD in it so I don't feel bad leaving it running. However ... I'd like Apache to host the web service, not the development server. SO, I followed all the instruction for installing WSGI and the sample HelloWorld.py file ran fine from any PC. Since that worked, I thought I'd follow the same steps and install the Flask app. <maniacal laughter> Nope. Crickets. 192.168.1.x/test_wsgi works fine. 192.168.1.x:8090/media/?id=5 (for example) gives me 'Refused to connect' or something less than optimal.

Perused through all the 'Installing Flask app' articles posted on Google. Changed .conf files, <VirtualHost> entries, ya-da-ya-da... Crickets.

My next step, when I calm down about all the wasted mornings spent trying to get it to work, will be to undo all the mods and try again (even though I've done that a few times already). Oh, I forgot to mention that initially this DID work! But I made a change to the .py file and deployed it back to Linux. Bang. Crickets.

Is there a definitive guide *somewhere* about installing Flask (or any Python file) on Linux? I know I have the sample running fine, but there are no log entries with errors when I try to run my app. It's as though Apache is port-deaf to my :8090. Why did I choose that port? No reason. Port 80 serves up the Svelte app.

So for the foreseeable future, I'm leaving the Linux box running and the REST api is being served by a terminal session running the development server on port :8090.
Reply
#2
The Digital Ocean guides are fine as start and blank Linux distro eg Ubuntu from 16 to 20.
So this can be applied other places even if not using DO.

This is in general a preferred setup and what i used several times.
How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 20.04
Which WSGI server should I use?
Quote:Gunicorn on the other hand,does exactly what you want and no more.
It is simple and works fine.
So I recommend it unless in your particular case there is a compelling reason to use one of the others.

The other one that is good is using uWSGI.
How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 20.04
Both has no Apache which is very fine Wink

If you search will find Apache setup to,but maybe not so updates as setup's over are preferred.
Deploy a Flask Application on an Ubuntu VPS (DigitalOcean)
Minimal Apache configuration for deploying a flask app (Ubuntu 18.04)
Deploying a Python app on a Digital Ocean production server
Reply
#3
Thanks. I've been to all the Apache 'How To' articles and did what they said to do. Nothing. Has to be a configuration issue that's elusive to the Linux/Python/Apache2 newbie (me). I think I will take your advice and try uWSGI or Gunicorn.

Actually, though, I think it's that Apache isn't listening on my port. The reason I think so is that if I change my .py file to run on port 8090 and run it from terminal mode, it should compllain that the port is already in use. It doesn't. So, methinks that this is an Apache config issue and nothing to do with flask or python. I should probably delete this post and head over to the Apache forums (if they exist).
Reply
#4
Hi lmolter54

What ports do you see running when you do a netstat in the Ubuntu terminal (there are various options to show the data), but a simple netstat -a will give you the port listening and those connected (established)

You may need to install the package to allow this, which would be - $sudo apt-get install net-tools
This package also gives you ifconfig which is sort of deprecated in favour of $sudo ip address show but i prefer the old way ;)
Regards
-------- *
“Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.”
Reply
#5
My port 8090 was not listed with netstat. So, while driving to the store, I had an epiphany -- why do I need a special port? It's on a server behind my firewall, and only my wife and I will be using it. So I removed the VirtualHost stuff for 8090. Had to make an adjustment to the routes in flask, but now it answers on port 80 and I'm a happy camper. With the back-end fixed, I can put more time into the front-end (Svelte) app. A few GUI issues there. But thanks for replying.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Flask, Self-hosted deployment, which server ? SpongeB0B 1 2,957 Apr-11-2021, 11:29 AM
Last Post: snippsat
  Django deployment on apache server? tmmaersk 2 2,075 Mar-28-2020, 03:35 PM
Last Post: tmmaersk
  Django Deployment Problem DoktorSoosMann 0 1,926 Aug-16-2018, 01:42 PM
Last Post: DoktorSoosMann

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020