How to Deploy a Flask App to a Linux Server

Tech With Tim · 186K views · 2019 · 22:12

Open on YouTube

Web developmentCloud, DevOps & reliabilityPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the step-by-step guide they followed when deploying Flask with Apache and mod_wsgi, and then ask about the errors they hit along the way.

Recommended by 1 people across 1 different months, 2020 to 2023.

What it is

A 22-minute Tech With Tim tutorial that walks through deploying a Flask app to a headless Ubuntu server on Linode. It covers installing Apache and mod_wsgi, configuring the firewall, transferring files with WinSCP, and enabling a virtual host.

What people said

Recommends ThomasATU · 2020-09 · Stack Overflow · on “Flask app working on local server but not globally”

Have you had a look at the Heroku docs regarding camera interfaces? There is an add-on CameraTag Heroku Cameratag [LINK] Also you might find self-hosting your flask app on an apache2 server a more successful solution. There are many tutorials and the process is not difficult. Heroku is great, but with my experience with face_recognition specifically, if you don't pay for upgrades you will run into issues exceeding memory <550mb. This link here is a great tutorial for self-hosting flask app. Deploy Flask to Apache Server [this video] Furthermore, it may be that Heroku cannot access the local camera peripheral or the device is no longer [0] # Using OpenCV to capture from device 0. self.stream = Web

Cites JohnCroc · 2020-06 · Stack Overflow · on “Problem getting mod-wsgi to run an app written using python3”

I've been hacking away at this for a couple weeks now. I got mod_wsgi working using these instructions [LINK] and and this YouTube video [this video] . When I used what I had learned to put my own application into play on my web-server, I had some problems but worked through most of them. The "stopper" was that I had written my application for Python 3.6 and the imports caused errors because mod_wsgi was trying to run them with Python 2.7. Further study made me aware that I needed to install libapache2-mod-wsgi-py3 instead of libapache2-mod-wsgi . At least, that's what I thought from what I read here [LINK] . Now, I have a new error: ubuntu@ip-172-26-13-175:~$ sudo systemctl start apache2 Job for

Cites Reda · 2020-06 · Stack Overflow · on “Deploying Flask app on own Ubuntu Server Error”

GOAL : I am trying to deploy my Flask app to make it public on the web. I have my own server which runs on Ubuntu 18.04 TUTORIAL : As it is the first time I am doing this, I am following this tutorial [this video] . All his steps are perfectly working for me except the last one. However, in this tutorial he used Linode and I use my own server so I directly code on my terminal PROBLEM : In his last step after systemctl reload apache2 when I go on the my browser and type my ip address (found using ifconfig) that I put in webApp.conf (192.168.1.25) I get the following error : [LINK] ERROR LOGS : As asked I went into the error.log which outputs the following : [LINK] You can find the code here : [LIN

Cites lolaa · 2020-07 · Stack Overflow · on “Flask Template Folder Not Found”

I am trying to deploy my flask app so that it is available on any computers in my LAN. However, when I execute it I get the following error in the apache2 error.log file : [LINK] The architecture of my app is the following: [LINK] This is for __init__.py (python3) : from flask import Flask, redirect, url_for, render_template,request app = Flask('__name__') @app.route("/", methods=["POST", "GET"]) def home(): if request.method == "POST": return render_template("index.html") else: return render_template("index2.html") if __name__ == "__main__": app.run() And my code index.html is : <!DOCTYPE html> <html> <head></head> <body> <h1>Home Page</h1> <form action="#" method="post"> <input type="submi

Cites Zeeshan Ali · 2021-07 · Stack Overflow · on “Unable to redirect to __init__.py while uploading flask app on ubuntu server”

I am very new to web development and I am following these two methods (both are same) to deploy flask app to ubuntu vps. [LINK] [this video] my folder structure is like this: |--------cwh |----------------cwh |-----------------------static |-----------------------templates |-----------------------venv |-----------------------__init__.py |----------------cwh.wsgi Below is my code of __init__.py : from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return "Hello, I love my first website!" Below is my code of cwh.wsgi file: #!/usr/bin/python3 import sys import logging logging.basicConfig(stream=sys.stderr) sys.path.insert(0,"/var/www/cwh/") from cwh import app as applica

Cites JamesDockett · 2021-10 · Stack Overflow · on “Site Does Not Exist: Flask app on Apache 2.4.29 Ubuntu 18.04”

I have looked at all the previous StackOverflow questions regarding this problem but cannot seem to find a solution in any of the answers. When I run the command: sudo a2ensite WebApp I receive: ERROR: Site WebApp does not exist! This is my file /etc/apache2/sites-available/WebApp: <VirtualHost *:80> ServerName 192.168.1.107 ServerAdmin email@mywebsite.com WSGIScriptAlias / /var/www/WebApp/WebApp.wsgi <Directory /var/www/WebApp/WebApp/> Require all granted </Directory> Alias /static /var/www/WebApp/WebApp/website/static <Directory /var/www/WebApp/WebApp/website/static/> Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log

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] [this video] [LINK] Also remember to activate your SSL/TLS certificate (easy way to do that would be for example certbot) and enable HSTS.