Python Flask Tutorial: Deploying Your Application (Option #1) - Deploy to a Linux Server

Python Flask Tutorial: Deploying Your Application (Option #1) - Deploy to a Linux Server

Corey Schafer

5 лет назад

343,610 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@CodeLegg
@CodeLegg - 08.01.2024 15:43

Request: Please create a video on migrating the DB to PostgreSQL. In the initial videos of this series, you mentioned that you will show how to use Postgres. Eagerly waiting for this :D

Ответить
@TruongGPT
@TruongGPT - 05.01.2024 20:29

tbh, this dude's voice is like a calm Trump

Ответить
@TruongGPT
@TruongGPT - 05.01.2024 20:29

tbh, this dude's voice is like a calm Trump

Ответить
@teclote
@teclote - 19.12.2023 21:55

Oh my God it's working, thank you, thank you.

Ответить
@howards5205
@howards5205 - 08.10.2023 02:27

I appreciate your thorough guide and doing everything the right way. So many tutorials skip over every other detail and just show the bare minimum. I like how your video shows all the best practices. Thank you!

Ответить
@emirafiq5358
@emirafiq5358 - 30.09.2023 23:01

doing a cloud engineering final project at the moment and needed a guide for NGINX configurations. i did mine on an EC2 and it works!! tq

Ответить
@learnmore5438
@learnmore5438 - 21.08.2023 12:26

i cannot get my env. I'm missing this part. It returns none

Ответить
@markakbarov3570
@markakbarov3570 - 07.07.2023 00:00

thank you for this awesome content. you wouldn't believe how many times I came back to this video for reference.

Ответить
@kamikaze9271
@kamikaze9271 - 15.06.2023 04:48

Okay so I faced some weird error. I'm on AWS t2.mirco Ubuntu and I checked that I have one core. I setup gunicorn just as mentioned but then when I started testing my website, it started acting strange. For instance when I click on the username from homepage multiple times, it automatically logged me in and then when I clicked on Account page, it displayed that I need to login but still had me logged in.

I changed the number of workers to one and that worked for me. Not sure what this is.

Ответить
@TO-il3vc
@TO-il3vc - 25.04.2023 22:37

I had a lot of trouble with the server configuration and SSH. Even after disallowing password login in /etc/ssh/sshd_config, if i delete my local .ssh folder, it still asks me for a password and lets me log in with password to the Linode server.

I got stuck at this command: sudo systemctl restart sshd
Seems the command is either outdated or just doesn't work. So i attempted to re-install SSH on the cloud server, but the command still did not work. It did cause a whole mess of re-configuring the SSH files though, which i did. But i was very concerned that it just let me log in to the server without a password or anything, all i had to do was delete my local .ssh folder... seems like a gaping hole in the security.

Ответить
@petronjuno8938
@petronjuno8938 - 06.04.2023 14:56

403 forbidden for static file

Ответить
@john-peterkrause7237
@john-peterkrause7237 - 13.01.2023 11:54

This video has helped me soooo much, thank you Corey!

Ответить
@sirico
@sirico - 04.01.2023 11:49

2023 and this series is still relevant thank you, Corey.

Ответить
@mudassiraqeel8604
@mudassiraqeel8604 - 21.12.2022 07:19

Can we get a flask-react application

Ответить
@JrPlays
@JrPlays - 02.12.2022 12:35

This may be an old tutorial but, I have my css in a similar file structure, and put that pathway into the /etc/nginx/sites-enabled/flaskblog. However my ngnix cannot bring up any custom css only the bootstrap, as I get a 403 badgateway on the css. Was there no permissions we needed to give?

Ответить
@pradipwaghela4045
@pradipwaghela4045 - 16.11.2022 13:04

Hey .
What is best practice for deploying react(Frontend) + flask(Backend) application on production?

Ответить
@senX
@senX - 26.10.2022 16:59

i know im late to the party, but this is as much as you can learn in an hour about a linux backend/deployment. it was usefull to me 4 years later, thanks a lot!

Ответить
@erasemelater
@erasemelater - 24.10.2022 15:50

So I was able to pass Supervisor step.
here what worked for me

We need to set software called SuperVisor
Under (venv) YOUR_USER@flask-server:~/YOUR_PROJECT$

Type: sudo apt install supervisor
Uninstall supervisor:
sudo apt-get remove supervisor
sudo apt-get purge supervisor

Installed pip for python3:
sudo apt update && sudo apt install python3-pip

Install supervisor using pip:
pip install supervisor

Install supervisor again using apt-get:
sudo apt-get install supervisor


Setup config file for SuperVisor
Type: sudo nano /etc/supervisor/conf.d/flaskapp.conf

And add following text:
[program:flaskapp]
directory=/home/YOUR_USER/YOUR_PROJECT/
command=/home/YOUR_USER/YOUR_PROJECT/venv/bin/gunicorn -w 3 my_app:app
user=YOUR_USER
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/flaskapp/flaskapp.err.log
stdout_logfile=/var/log/flaskapp/flaskapp.out.log
startsecs=1

Note, there is closing back slash at the end of path to your project for directory=
under command= is a place where gunicorn is located. To double-check it run in bash: whereis gunicorn. See where it is located and check with what you have in command=

my_app:app , where my_app is the folder if you use package content. Inside of that folder you will have a __init__.py file. Inside that file you will have app. Where app = Flask(__name__). If you dont use packaged structure, then just a filename where this code is located app = Flask(__name__).
user=YOUR_USER is your ubuntu user that you created after root.


CTRL+X, Y, Enter to save

We want to create log files quick:
Under (venv) deadok@flask-server:~/Interactive_brokers_PIT38$
Type: sudo mkdir -p /var/log/flaskapp
Type: sudo touch /var/log/flaskapp/flaskapp.err.log
Type: sudo touch /var/log/ flaskapp /flaskapp.out.log


Restart our Supervisor:
Type: sudo supervisorctl reload (Restarted supervisord)

You need to wait 10-20 seconds and check your site. Should work.

Ответить
@Juanoetdm
@Juanoetdm - 18.10.2022 21:28

Corey, thank you so much for your videos. More than helpful.

Ответить
@jakubkrajewski8249
@jakubkrajewski8249 - 10.10.2022 23:42

like man i respect you so much

Ответить
@jakubkrajewski8249
@jakubkrajewski8249 - 10.10.2022 23:30

spend white day fighting and reading dogshit articles only to see the of made this vids

Ответить
@jonbrenner565
@jonbrenner565 - 07.10.2022 22:29

Has anyone else had trouble with 502 bad gateway errors after deploying updates? I can't seem to get it back up and running :(

Ответить
@Villentrethenmerth
@Villentrethenmerth - 04.10.2022 10:28

I've seen using "--daemon" optional parameter when running gunicorn instead of Supervisor. Any thoughts on differences anybody?

Ответить
@kia4now
@kia4now - 02.10.2022 18:01

There are so many short "to the point videos" out there but I really appreciate what you did Corey, for us new guys it's helpful how you show best practices and all the little details. This is so helpful, especially for those that are not familiar with linux

Ответить
@simoneonorato1223
@simoneonorato1223 - 29.09.2022 21:36

This video is like the bible. To follow step by step when launching a Flask app! Thanks man!

Ответить
@kylersuden2713
@kylersuden2713 - 17.09.2022 07:15

Really wish you would do this same tutorial with a postgres database. SQLite is pretty impractical for any application with intention of actually reaching users and getting the postgres to work on the remote is giving me so much trouble.

Ответить
@hamadyounus1103
@hamadyounus1103 - 25.08.2022 15:55

you are owwwwe
some

Ответить
@swaraankshita3830
@swaraankshita3830 - 18.08.2022 15:45

Can you make a video on deployment using heroku for flask ? I tried to follow along your django heroku deployment video but flask does not really have anything like django storage so I am not really getting how to store uploaded files on s3

Ответить
@r3xtez987
@r3xtez987 - 15.08.2022 19:13

I can't believe you're providing this high quality content for free! I'm supporting your channel to Patreon and recommend others to do so too!

Ответить
@oyelereoluwabiyi2684
@oyelereoluwabiyi2684 - 07.08.2022 08:45

@Corey Schafer, many thanks for the time and effort put into the tutorial, I have a question though. Did you exclude the venv from your local system while moving the file to the linux server and did we have to recreate the venv folder on linux if there is already a working version from the local system

Ответить
@deepgrowth353
@deepgrowth353 - 13.07.2022 03:05

I am getting a 403 nginx error when accessing static folder (minute 56-57)

Ответить
@GabrielSantos-js7kk
@GabrielSantos-js7kk - 13.06.2022 04:16

After many hours searching for how to deploy my project, I find everything I need right here.
Amazing work Corey :D

Ответить
@wild_elliot
@wild_elliot - 12.06.2022 22:25

This Video is intresting already => shows how configuring your servers and the connectivity between the two securely as much as permissions work but it needs the ACL ones.... as well as deploying your web application ,, Good job and nice video

Ответить
@charlesE89
@charlesE89 - 01.06.2022 09:05

Anyone else having problems getting nginx to restart? I just keep getting failures. I've been asking over the interwebs and unable to find a solution yet

Ответить
@icy-spoon85
@icy-spoon85 - 31.05.2022 12:13

How common is it to use supervisor? What viable alternatives are there for this? E.g. would it be common to use docker to run this?

Ответить
@llIIllIlIIllX_XIillIIllIIllIll
@llIIllIlIIllX_XIillIIllIIllIll - 14.04.2022 23:50

I dont say that alot, thank you for doing this
the extra stuff that I don't need right now might be useful in the future but it didn't bother me at all, I just skipped it

Ответить
@RodolfoMezaP
@RodolfoMezaP - 17.03.2022 00:42

Corey, Thank you isn't enough to express my acknowledgement of this video, and how do you explain this topic.

Ответить
@joe_shmo_10
@joe_shmo_10 - 08.03.2022 04:19

I deployed to google cloud platform and when a user tried to create an acount on the deployed version there is an error "OperationalError: attempt to write a readonly database". Does anyone know how deal with this or what is going on?

Ответить
@DanKardell
@DanKardell - 14.02.2022 17:57

Great job. Question at 17:xx you issue a ssh-keygen and overwrite your existing id_rsa file. Won't that now invalidate any other systems that you used that id_rsa file in because you overwrote it, thus locking you outout of other servers? Why would you not use your existing id_rsa file?

Ответить
@jschoi9290
@jschoi9290 - 25.01.2022 10:53

Corey, just wanted to say I think you're the best Python teacher out there and I really appreciate all your videos (and I'm supporting via Patreon - although in small amounts - to show my appreciation). Take it easy and come back when you're ready to come back.

Ответить
@orangemahrt
@orangemahrt - 10.01.2022 01:34

I'm running into a litany of complications with Nginx permissions. My site works perfectly on 5000 in dev then starts running into 403 errors once on 8000, and I can't seem to pass the login page. The stderr and stdout files aren't very clear either. This whole tutorial is amazing... but I'm really struggling to walk away from it knowing what Nginx is actually doing, especially after hours of external research to no avail. I think I've become a bit spoiled with your quality of teaching and am struggling to get answers elsewhere. Would love to see a video from you on Nginx permissions, and maybe just server/user permissions in general. Thank you so much, Corey!!!!

Ответить