Тёмный

How to Deploy a Flask App to a Linux Server 

Tech With Tim
Подписаться 1,5 млн
Просмотров 166 тыс.
50% 1

This video will show you how to deploy your flask app to a headless linux server that is running ubuntu. We will be using apache and wsgi to do so.
Thanks to Linode for sponsoring this video! Deploy your linux server by clicking the link or using the promo code TWT19 for $20 free credit!
linode.com/techwithtim
Playlist: • Flask Tutorial #1 - Ho...
Download Links:
www.putty.org/
winscp.net/eng/download.php
Credits:
www.digitalocean.com/communit...
*Procedure (refer to video for missing details)*
Step 1: Setup a server on linode
Step 2: Download Putty and SSH in
Step 3: Download and Install Apache
- sudo apt update
- sudo apt install apache2
- apache2 -version
Step 4: Configure Firewall
- sudo ufw app list
- sudo ufw allow ‘Apache’
Step 5: Configure apache
- sudo systemctl status apache 2
Step 6: Install and enable mod_wsgi
- sudo apt-get install libapache2-mod-wsgi python-dev
Step 7: Creating flask app
- cd /var/www
- sudo mkdir webApp
- cd webApp
Step 8: Install flask
- sudo apt-get install python-pip
- sudo pip install Flask
- sudo pip install flask_sqlalchemy
Step 9: Use winSCP to transfer python files to server
Step 10: configure and enable virtual host
- sudo nano /etc/apache2/sites-available/webApp.conf
CLICK TO DOWNLOAD THE CODE TO PUT IN webApp.conf
dev-cms.us-east-1.linodeobjec...
- sudo a2ensite webApp
- systemctl reload apache2
Step 11: Create .wsgi file
- sudo nano webapp.wsgi
Place the below code in the wsgi file
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/webApp/")
from webApp import app as application
application.secret_key = 'Add your secret key'
Step 12: Restart apache
- sudo service apache2 restart
Step 13: Visit the ip address of your server in the browser to access your website!
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
tech-with-tim.teachable.com/p...
📸 Instagram: / tech_with_tim
🌎 Website techwithtim.net
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-rusci. .
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
💵 One-Time Donations: www.paypal.com/donate/?token=...
💰 Patreon: / techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
Tags:
- Tech With Tim
- How to deploy a flask app to linux
- Deploy flask app
- Flask App Deploy
- Deploy flask app to ubuntu server
#Python #Flask #Linux

Опубликовано:

 

22 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 199   
@hexa3389
@hexa3389 2 года назад
Madman typing sudo while root. True sigma grindset.
@lucaspham5238
@lucaspham5238 4 года назад
this is such an underrated channel
@wertuxhd6201
@wertuxhd6201 3 года назад
definetely..
@meleseberehannu2861
@meleseberehannu2861 3 года назад
more important than other people think
@mohammadfallah.rasoulnejad5379
@mohammadfallah.rasoulnejad5379 3 года назад
it is! fo sure.
@michaelmark1038
@michaelmark1038 3 года назад
It same with use hosting :)), so bad!
@truthhorizon5851
@truthhorizon5851 3 года назад
@Rizwan Mustafa Why?
@johncrockett8308
@johncrockett8308 4 года назад
THIS was SO helpful. Thanks you! I have come back and referenced it, like, a hundred times!
@ThilinaWimalapriya
@ThilinaWimalapriya 4 года назад
The best simple and powerful tutorial I found yet for deploying flask in ubuntu. Thank you very much for sharing this.
@JuanSidberry
@JuanSidberry 4 года назад
Tim, you're doing a great job! There is a lot of valuable/helpful content on this channel. Keep it up. Hint: -y when using apt-get install. But this is for experienced users who know they want to say YES to the prompt.
@LynxGuy
@LynxGuy 2 года назад
also he was already logged in as root
@anshulpatil2808
@anshulpatil2808 3 года назад
This is the best Flask tutorial available on youtube. Thanks Tim!!
@Max-oj9tp
@Max-oj9tp 4 года назад
Thnx Tim, these videos really helped me understand the setup of a Ubuntu server!
@JamesFraze
@JamesFraze 2 года назад
I've followed the series in this and learned quite a bit about flask. Just a quick note that if you are "root" you don't need to type sudo. A security tutorial would be great because there are many things that can be improved on this section. Otherwise, great work, great explanations!
@cperzam7700
@cperzam7700 4 года назад
Hi Tim, I'm so glad I came across with your channel I was looking for this for a couple of days with barely any success. Thank you very much you have my like!
@naweendanushka3358
@naweendanushka3358 Год назад
Thanks tim for your video series . It is very helpful
@CabalBoone
@CabalBoone Год назад
That was very pleasurable, thank you.
@matijaziberna1512
@matijaziberna1512 4 года назад
Thank you, man! After going through sh**tton of articles, I made it to work with your video!
@mohammadfallah.rasoulnejad5379
@mohammadfallah.rasoulnejad5379 3 года назад
very detailed explain by example! specially the details about the mistakes that we might get ourselves into.
@terribleturtles
@terribleturtles 4 года назад
I can't wait to see what you've got for us next!
@WaldoTheWombat
@WaldoTheWombat 3 года назад
Nice username
@koushik7604
@koushik7604 3 года назад
Great stuff 👍, you just saved me bro for office project deployment
@kamolusmonov6540
@kamolusmonov6540 4 года назад
I have been thinking about it over a years :D Now I got ) Thanks
@Ben7o711X
@Ben7o711X 4 года назад
thanks for the tuto men ! you're better than most of my teatchers haha
@brendanjensen1721
@brendanjensen1721 4 года назад
This series is great. One comment, at around 16:00, you mention that for nano the exit command for Macs can be Ctrl+X or Cmd+X, which isn't correct. You have to use Ctrl+X. Same with all nano commands, need to use Ctrl. I've learned a lot from your series! Keep it up.
@Dani-cr7cj
@Dani-cr7cj 2 года назад
Amazing playlist, thank you Tim. I hope to see the update version - Or comments about what has changed. Thank you very much.
@mikhailshkaralevich574
@mikhailshkaralevich574 2 года назад
Thank you! Your tutorial is great!
@jonashaas4681
@jonashaas4681 4 года назад
In case you are facing the issue that the "Apache2 Debian Default Page" displays do: sudo a2dissite 000-default.conf to disable the default configuration for apache
@tactiletech1111
@tactiletech1111 3 года назад
ty tim great content as always
@potthegreen
@potthegreen 2 года назад
thanks Tim, I have a secure apache home server and I've been struggling to get my django and flask apps running online. I will give it a shot with your configs!
@polarpenguin7596
@polarpenguin7596 2 года назад
fantastic tutorial!!
@benjaminmcgregor1250
@benjaminmcgregor1250 3 года назад
In the previous tutorials we had a file named 'main.py' in the root folder with __init__.py blank in the admin folder to make it a package. Where has this init file come from?
@miguelribeiro1506
@miguelribeiro1506 4 года назад
Really helpfull man, thanks!
@muhammadanique2256
@muhammadanique2256 3 года назад
Hi Tim , I was following your flask tutorial , the last video where you host the side , is it valid for Django apps as well or is it limited for only flask apps?
@magnesiumfilmsltc1530
@magnesiumfilmsltc1530 4 года назад
Could you recommend any tutorial for setting up the custom domain?
@philippevanschendel4904
@philippevanschendel4904 4 года назад
Great tuto !! Thanks
@wilsongoins6398
@wilsongoins6398 7 месяцев назад
Following this tutorial in December of 2023 - The command at 8:30 did not work for me on Windowsx86 64bit. This command worked instead "sudo apt-get install libapache2-mod-wsgi-py3 python-dev-is-python3"
@AzlanCoding
@AzlanCoding Год назад
Hi, thanks for your video. It really helped me set it up in my 1st generation iPad air. However, I would like to set up openssh's SFTP. How can I do this?
@SpooningTreesap86
@SpooningTreesap86 3 года назад
Does anybody know if this will work if I deploy my flask app (which is a simple REST API to handle incoming POST requests only) using this method but then reference the server IP from my front end which is on a separate server? Meaning I have a single page html/JS page which enables an AJAX post request that successfully is handled by flask on a separate server? In practice I have it working putting my flask app on loaclhost port 5000 and my front end on port 5500. The only part that concerns me is how the templates folder is required, yet I won't be displaying any html from this server.
@adamk8881
@adamk8881 3 года назад
THANK YOU SO MUCH!!!! 🐐
@stefanherbek2025
@stefanherbek2025 3 года назад
Hi, great video. Thank you very much! Does this also work for Dash (Plotly Dash) Apps? Dash is based on Flask.
@ericfricke4512
@ericfricke4512 4 года назад
Awesome! Thanks.
@jmsolorzano13
@jmsolorzano13 3 года назад
Great video... If I have a flask rest api, Can I use the same deploy process?
@luciaravazzi6925
@luciaravazzi6925 2 года назад
Very cool man!!
@abeilcoelho8625
@abeilcoelho8625 3 года назад
What if we need to run more than one app on a server and/or on different ports? Thanks!
@udaysankarg8269
@udaysankarg8269 3 года назад
Tim, Can you also tell us how to deploy using docker containers - Flask app + DB and deploy on Cloud if possible
@prawnydagrate
@prawnydagrate 4 года назад
Now I've fixed it, but Flask SQLAlchemy fails to open my database file because it doesn't have permission. Does anyone know what I am supposed to do?
@_b0mbix_
@_b0mbix_ 4 года назад
Can I do everything same on own Ubuntu when I've static IP?
@andreig3370
@andreig3370 4 года назад
Hi Tim! Thanks for that video, that was very helpful, but I have one question. Must I create a folder called 'static' or not? If yes, what should I put inside of it? I have my Flask app, but I have only a 'template' folder and this is enough for me. Is it correct or should I reconfigure it somehow? Thanks for your help!
@ryperson269
@ryperson269 Год назад
static is for stuff like css and images
@koheisuzuki6355
@koheisuzuki6355 3 года назад
Can you create a short video or a blog post about how to deploy with a virtualenv on apache with concreate examples?
@anirudhpai2774
@anirudhpai2774 3 года назад
Thank you so much!
@michaels8297
@michaels8297 3 года назад
Linode is one of America’s greatest companies IMO
@aplombsunny
@aplombsunny 4 года назад
How to handle multithreading in flask app on production server?
@jadhavsuyu
@jadhavsuyu 4 года назад
Hello sir, can you teach us how to build API using neo4j...
@eolnuha
@eolnuha 3 года назад
why when I try to write my sqlite3 database it says "attempt to write a readonly database"?
@johnbryan1523
@johnbryan1523 6 месяцев назад
Thanks!
@johnbryan1523
@johnbryan1523 6 месяцев назад
Wow great series for a noob in the Python. Currently working with Akamai(formerly Linode) as you have referenced in this final great video. Why didn't you select the LAMP setup? Any particular reason? I set my stuff up using your recommendations, but a service ticket reply from Akamai asked if I knew they had it. Again, appreciate your help!
@dawnbugay7094
@dawnbugay7094 4 года назад
is this will work in machine learning to deploy it like this?
@pradeeptabhattacharya9657
@pradeeptabhattacharya9657 4 года назад
Please make a video on flask-sijax. I actually understand your tutorial and I am having a problem with understanding sijax.
@JT-qi4xx
@JT-qi4xx Год назад
Thanks @Tim. very helpful guide! however cmd: sudo apt-get install libapache2-mod-wsgi python-dev didnt work for me because of python3 I guess. so did cmd: sudo apt-get install libapache2-mod-wsgi-py3 instead and it did work. Thanks. you are the best
@Francothezebra47
@Francothezebra47 11 месяцев назад
Needed this, thank you
@backstepjedi369
@backstepjedi369 7 месяцев назад
thanks needed this as well
@iTzBenJii
@iTzBenJii Месяц назад
Ty
@aidans4953
@aidans4953 3 года назад
> cannot import name app Doesn't work, any tips?
@tobiapioscivoletto3686
@tobiapioscivoletto3686 2 года назад
Hi Tech, my script give me problem with Flask Session. The server response with a PermissionError: Permission Denied "/flask_session". I've tried all but nothing
@thomassmith9487
@thomassmith9487 3 года назад
Why do you use Putty instead of just sshing in through command prompt?
@bikeanime5126
@bikeanime5126 3 года назад
I had hosted my site using this Apache but I am getting Hello World program instead of my actual web site ... Could you help me ?
@jakemayr1
@jakemayr1 3 года назад
I'm confused, where did the __init__.py files come from, where did the views folder come from, and is there a setup.py that's needed?
@mohammadfallah.rasoulnejad5379
@mohammadfallah.rasoulnejad5379 3 года назад
I'm not sure what you're talking about but if you mean the contents of "/var/www/webApp/webApp" folder that's the flask app. this video was about running a flask app on Apache remember? so you need to have an app to run. that's the one.
@jakemayr1
@jakemayr1 3 года назад
@@mohammadfallah.rasoulnejad5379 In his past tutorials he didn't go over the __init__.py or setup.py files, just his main flask file so I was wondering about that part of the setup. This video is a part of a series he did as he mentions at the beginning of the video :)
@aviwesiyandiba5426
@aviwesiyandiba5426 3 года назад
Did you manage to figure that up? I have the same problem
@Gamerimkarton
@Gamerimkarton 3 года назад
I have an homeserver but just have the local IP, how can i get the right Ip ? because it wont work with the local ip
@dolodestinations7628
@dolodestinations7628 5 месяцев назад
Tim, Do you have any videos on how to configure a linode server? I added the certificate from letsencrypt and browser works great, but mobile is being blocked. It has something to do with the IPV4 vs IPV6 connection. IPV6 is being blocked. Letsencrypt only has forums, and no one is giving an answer. Please help! Thank you,
@dawnbugay2288
@dawnbugay2288 4 года назад
Is this get all dependencies of your app?
@user-bc2ec6dg4e
@user-bc2ec6dg4e 4 года назад
Now how can I see that website you made?
@mnlevi
@mnlevi 3 года назад
Thank's Sheldon Cooper.
@yassermunoz1984
@yassermunoz1984 3 года назад
ya lo tengo desplegado pero no me muestra la pagina cuando me redirecciona\
@user-cd7hz8mt7c
@user-cd7hz8mt7c 3 года назад
sudo is not necessary if you work under superuser, isn't?
@quandoeuforrico
@quandoeuforrico 4 года назад
00:00 Hello people. (lol) I don't know what Linux is, but I'll watch this video! Thank you!
@benjaminzwier342
@benjaminzwier342 15 дней назад
so is anyone else not able to get the page to show html files from the template folder? it is running from the thml folder in the first webApp folder, even though i did everything exaclty the same as tim.
@ramakiran3
@ramakiran3 3 года назад
Hi... Please tell me, how to do deploy flask web application in windows IIS... please help me on this... You help is highly appreciated 🙏😊❤
@fvgoya
@fvgoya 4 года назад
So, if we use Flask (Python), we will always need to have APACHE (which is manly to run PHP) to run Flask? Does not exist a server for Python, like Apache for PHP or Node for JavaScript??
@Asmayra
@Asmayra 4 года назад
The more common approach would be to use gunicorn as a webserver and nginx as a reverse proxy. Miguel Grinberg has a good guide on this in his Flask Mega Tutorial (Chapter 17).
@narekzamanyan893
@narekzamanyan893 2 года назад
Thank you!!!
@jermeekable
@jermeekable 4 года назад
I like what you are doing but id like to know the cli way all the way through. Copy Pasta in gui to get files on ur server is not as useful as knowing how to pull from git for instance. Anyways thanks for the vids, they are helpful. I have been digging youtube for weeks for good ubuntu server vids. Good ones are rare. Most I find are one off vids on how to install ubuntu server or terminal basics. I really hope you fill the niche. Ive only found two other playlists that get beyond basics helpful. But this is the only one ive seen touch flask. I managed to deploy a flask app to my server with gunicorn but dont know the diff between what I did n using apache. Or how to set up postgres locally on the server and connect to it. I guess I will just read what I need to know when the time comes but would much rather learn about it by watching a dope youtube lecture!!!
@learntodeveloper
@learntodeveloper 4 года назад
this case python base on run 2.7.5 pls how to run python 3.6 base on
@liamcodes
@liamcodes 4 года назад
in your webapp.wsgi file, change the top line from #!/usr/bin/python to #!/usr/bin/python3 (given that you have python3 installed on your server.
@foreverkatiexx3
@foreverkatiexx3 4 года назад
I keep getting this error: "No supporting authentication methods available (server sent: publickey)" . Any ideas on why I'm getting this and how to fix it?
@yakoubazzouni7889
@yakoubazzouni7889 3 года назад
on advanced add ur private key
@kukhokuhletsengwa5730
@kukhokuhletsengwa5730 4 года назад
Hi Tim. I have followed your video. However, I only see "Index of/ Name Last Modified Size Description" when I visit my IP Address in the browser. It is as though I do not have an html file, yet I know I have one. Please assist. Thanks for the awesome video.
@CavanMitchell
@CavanMitchell 2 года назад
did you figure this out? I have the same issue.
@gabalawy5
@gabalawy5 4 года назад
big thanks for you..
@liam1732
@liam1732 2 года назад
I want to kiss you computer server man, you have helped me greatly, keep up the helpful videos!
@TechWithTim
@TechWithTim 2 года назад
I’ll take likes instead ;)
@ta9995
@ta9995 2 года назад
error Not Found The requested URL was not found on this server.
@ririraman7
@ririraman7 2 года назад
Thank you.
@primaireernovembre
@primaireernovembre Год назад
hello...can you give me a video to how i can change the ip to my domain name !!
@mikefda12
@mikefda12 3 года назад
Can I do this with windows?
@intrinsic524
@intrinsic524 2 года назад
i think linode changed. apache error says "no module named flask" which is a python2 error
@louisdusanter8970
@louisdusanter8970 3 года назад
Hi, Thanks a lot for this great tuto. I want to deploy a python app on my vps and need the scipy module. The server is working great untill I add 'import scipy' in __init__.py file. (I have pip install scipy before on my vps). I just spent more than two hours on internet to find the solution, but nothing could help me. Someone here have the solution ? Thanks a lot !
@jamesorior
@jamesorior 3 года назад
Can you do plesk server CentOS Linux 7.8.2003 (Core)
@samuelepignone8255
@samuelepignone8255 4 года назад
PLEASE HELP ME!!! I follow all the steps but at the end I see the apache2 page and not my flask application
@evertonsilva2631
@evertonsilva2631 4 года назад
sudo a2dissite 000-default.conf to disable the default configuration for apache
@oscarwang7920
@oscarwang7920 4 года назад
so how to make changes in the python code once u put that on the server ?
@techbhanucomputer4389
@techbhanucomputer4389 3 года назад
edit the __init__.py file and restart apache. changes will bee uplyed
@vikupilot
@vikupilot 3 года назад
How to automate this through jenkins .
@jhoanmartinezsilva2609
@jhoanmartinezsilva2609 4 года назад
Please a crud tutorial in Django ✌️
@l30lxbrg
@l30lxbrg 3 года назад
TIM UR A REAL G 4 LIFGE
@saadkhan-ku8bl
@saadkhan-ku8bl 2 года назад
very nice
@WaldoTheWombat
@WaldoTheWombat 3 года назад
When typing the command: sudo apt-get install libapache2-mod-wsgi python-dev I get the following message: "Note, selecting 'python-dev-is-python2' instead of 'python-dev' Package libapache2-mod-wsgi is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source" Does it need to be: apt-get install libapache2-mod-wsgi-py3 ?
@thomaseardley2900
@thomaseardley2900 3 года назад
did you find out the answer to this because i have this problem to ?
@WaldoTheWombat
@WaldoTheWombat 3 года назад
@@thomaseardley2900 i think I eventually put in the command i wrote below and it worked
@SkyFly19853
@SkyFly19853 4 года назад
That's very very nice since I am a Linux user...
@prawnydagrate
@prawnydagrate 4 года назад
I keep getting ImportErrors like "No module named 'flask', referrer: *VM_IP* /" even though I've tried this many times. Does anyone know what I can do? I did try pasting Flask, Flask SQLAlchemy, and etc inside my project folder. But it kept generating other ImportErrors over and over.
@prawnydagrate
@prawnydagrate 3 года назад
@Ian Taylor I don't know. I think WSGI is like Python 2 because F-strings didn't work.
@prawnydagrate
@prawnydagrate 3 года назад
I forgot to say that I fixed it months ago. But I wanted to host my website for free so I used Heroku instead. I was doing the "sys.path.insert(...)" part wrong.
@bekhruzniyazov6600
@bekhruzniyazov6600 4 года назад
It's a lot better and easier to do it with Heroku but anyway a very good video like always
@gresliebear
@gresliebear 4 года назад
how do you change ip address to domain name?
@mehmetaliozer2403
@mehmetaliozer2403 4 года назад
+
@CatDevz
@CatDevz 4 года назад
SSL?
@ahmedthegreat3973
@ahmedthegreat3973 3 года назад
But I Want To Change My Domain Name/URL
@weaselwords3386
@weaselwords3386 2 года назад
Great tutorial - I ran into an issue on the winSCP part of moving files to the directory. Reason : lack of privileges and needing root. winSCP can inject a shell command at the point of connection under the Advanced setting within the session configuration. click Advanced then under the Environment > SCP/Shell option add the command to the shell: field in this case 'sudo su -' (this elevates the user id to root privileges at point of connection.)
@braydenuber3603
@braydenuber3603 2 года назад
i cant get the sql data base to work when its deployed it works on host but not on the server
@muhie
@muhie Год назад
@@braydenuber3603 yes i can read the database but not write to it, do you have the same issue/do you have a fix
@WireNut88
@WireNut88 Год назад
@@muhie You have to go into WinSCP on the files u need to write in, click on them individual once, then look for the properties option near the top right(not all the way top right). After you hit that in the permissions section, make sure all the W boxes are check marked. This files leading to that file have to have the permission to write as well(webApp file if that’s what u called it).
@muhie
@muhie Год назад
@@WireNut88 do you have to modify any of the wsgi file
@muhie
@muhie Год назад
@@WireNut88it works now thank you!!!!!
@techbhanucomputer4389
@techbhanucomputer4389 3 года назад
bro, i am 15 years. i don't have credit card. so, can you tell a provider that don't ask for credit ard? please if you can.
@WaldoTheWombat
@WaldoTheWombat 18 дней назад
Was anyone able to use this for deploying a web socket Flask application?
@tobiaszgleba5295
@tobiaszgleba5295 4 года назад
video description: step 5: err: sudo systemctl status apache 2 -> sudo systemctl status apache2
Далее
How to Deploy a Flask App to Linux (Apache and WSGI)
11:21
Laptops make GREAT Linux Servers
26:47
Просмотров 229 тыс.
Deploy your Flask app on Google Cloud Platform
17:51
Просмотров 13 тыс.
FastAPI, Flask or Django - Which Should You Use?
9:49