In this Python Django Tutorial, we will be learning how to deploy our application to a Linux Server from scratch using Linode.

If you would like $20 of free credit towards a Linode account, then you can use my link here to sign up:

We will be covering the entire deployment of a Django application. This includes spinning up a new Linux Server and tightening its security with SSH keys and firewalls. Then we will install Apache and Mod_WSGI so that we can get our Django App running. Let’s get started…

To skip the server setup, jump to 29:11

How to Run Linux/Bash on Windows:

SSH Key-Based Authentication Tutorial:

SSH Keys on Windows:

Apache config used in this video:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python #Django

Nguồn: https://codeigniterbrasil.com

Xem thêm bài viết khác: https://codeigniterbrasil.com/lap-trinh-linux/

43 Comments

Corey Schafer

April 29, 2020

In this video, we set up a Linux server from scratch before we deploy Django, which is what a lot of people have requested. But if you already have a server ready to go then you might not be interested in the setup part. If you'd like to skip the Linux server setup and go straight to the deployment then please skip to 29:11

Just be sure you make the code correction I mention at the 3:00 mark! Anyways, I hope people find this useful. Deployment can be a tricky topic because there are so many different choices (e.g. hosts, operating systems, web servers, etc). These are my preferred choices in this video. Remember, if you'd like to sign up for $20 of credit at Linode then you can use my link to signup: https://promo.linode.com/coreyschafer/

Reply

iNodeCode

April 29, 2020

all of my files dont seem to be transfering over, I tried moving forward with what was added to follow tutorial, and i keep getting snags at every step. Not sure how to fix it to get ALL files transfered over. i typed scp -r django_project1 user@address:~/ …but wont transfer all files.

Reply

Wojti Wojt

April 29, 2020

Hello Corey,

Thanks a lot for a great tutorial (i didn't find anything better than this on the web)!
I'm considering if using django's default database (created while starting an app) is safe enough, because i think it has no password? Could you refer to it? Thank you in advance!

Reply

FrameEater

April 29, 2020

It won't work, i copied the apache2 .conf file from your github, changed the names but it returns the default apache2 webpage

Reply

Jesse Martinez

April 29, 2020

Just curious if having the typo at 3:31(kawrgs instead of kwargs) caused any problems later? I guess the name doesn't matter if you're consistent with it.

Reply

Mike Kevin Castro

April 29, 2020

// Setting up a new server
set hostname 12:10
add user 14:20
permissions ssh 23:00
disable root login and password authentication 25:20
firewall 27:00

deployment 29:11

Reply

SANJAY OLI

April 29, 2020

can u please do a video with giving domain name and http all, coz its left on half way, it would be complete if u do that all rest in a vide, thank you soo much, waiting for this topic video

Reply

auriaks

April 29, 2020

Hey, Corey. Thanks for your effort on all videos as they are very informative and clear. I tried the setup from this video, but found it quite expensive (as I do not own a server). Do you have a video, showing how to publish this site having Hosting with no sudo privileges? Obviously server are shared and will not grant sudo for their users. Just let me know if it is securelly possible or not, if you do not have time to publish a video on that. Kind regards.

Reply

Snehal Adhyapak

April 29, 2020

Hey, this tutorial is great. I added my ip in hosts, but when I fire 'python manage.py runserver 0.0.0.0:8000', and desired ip in chrome, it says site cant be reached.
Id appreciate your help. Thanks

Reply

Jerry

April 29, 2020

This is the best Django deployment Tutorial I have ever seen. Corey the GOAT

Reply

Louis Grange

April 29, 2020

This is the best course ever on YouTube !!! Waw, you explain so well !!!

Reply

A I

April 29, 2020

I'm so thankful of you Corey. This course is so good.

Reply

TH

April 29, 2020

Hi! thanks for the amazing tutorial. I have one problem still. The css on my website is messed up (much like in the templates episode when you first ran it) in that episode you restarted the server and it was fixed, but that doesn't work. I restarted apache, the django server and even the complete linux server. Any ideas anyone?
EDIT: I made a typo in the apache .conf file 🙂 works fine now

Reply

Mees van der Ent

April 29, 2020

Thanks a lot for the clear, step-by-step explanation. Very good content!

Reply

Mike Kevin Castro

April 29, 2020

You are a god!

Reply

Idir AIT YAHIA

April 29, 2020

Hello

Firstly I want to thank you for this fabulous work, it's really a complete tutorial,

I have successfully completed all stages but I am blocking the deployment.,
I followed the steps step by step for the deployment, for me it was on a virtual machine under Ubuntu 18.09, the application run correctly when I use Django runserver
on browser i get an "Internal Server Error"
in my apache error log file a get a [wsgi:error ]this error
Target WSGI script ' path to my wsgi.py' cannot be loaded as Python module

Reply

gwulfwud

April 29, 2020

thank you very much, this is what every starting developer needs

Reply

GCN's Games

April 29, 2020

Hello I found this video and I would ask you this before starting. I have a project for the end of my school year, and this is to make a blogango on a website like you do or like wordpress. My question is, blangango it is equal to django ? I found lot of thing and what I found is it is the same thing but django is only for the page and blogango is for host.

Reply

Diego Bianchi

April 29, 2020

how can be visible my website on google ?

Reply

Zhou XF

April 29, 2020

somehow when I restart the apache2 server and visit my IP adress, I keep getting this error message "You don't have permission to access this resource." anyone got the same issue like I do?

Reply

Andy Paling

April 29, 2020

Hey, for some reason, everything is working, but when trying to send emails with password reset, it takes so long that it timeouts, can someone help pls.

Reply

Bill Fujimoto

April 29, 2020

I'm lagging behind everyone here… I'm having a problem getting things working properly once I moved the django project to the cloud, I'm hoping someone can give me a clue as to the problem.
Essentially, port 80 is not permitted when using Django as the dev server [ … runserver 0.0.0.0:80], or the http request is forbidden when using the Apache2 web server. I tried to follow explicitly what Corey was doing. It works when using localhost:8000 but nowhere else. I made sure the firewall did not block http/tcp on port 80, I used netstat utility to verify 80 was open and listening, ping works fine too.

This problem was pretty similar on both Linode and Google Cloud VM. Google server did not respond at all on port 80, Linode server said I don't have permission for this website. Somewhere something got crossed I guess. Anyone have any ideas? I'm pretty clueless at this point, I'm not a sw developer.

Reply

Deniz Utku Aktürk

April 29, 2020

Timestamps:

02:33 – Fixing the bug from previous video

04:17 – Creating Linode

08:05 – Ip Address and SSH Credentials

10:13 – Root Connection to the Server

11:09 – Installing Software Updates

12:10 – Setting Host Name

12:46 – Setting Host File

13:59 – Adding Limited User

16:27 – Setting Up SSH Key Based Authentication

22:45 – Setting Permissions for SSH Directory

25:00 – Forbiding Root Login & Password Authentication

26:43 – Setting Up a Firewall

29:10 – Putting Django Application on Webserver

30:15 – Generating requirements.txt File

32:41 – Copying Django Application on to the Webserver

34:46 – Creating Virtual Environment on the Server

36:52 – Installing Dependencies

37:49 – Changing Django Settings for Testing the Application on Django Server

39:51 – Collecting Static Files

40:23 – Testing Application

44:30 – Installing Apache & ModWSGI

46:04 – Configuring Apache Webserver

54:38 – Enabling Site Through Apache

55:29 – Setting Up File Permissions

58:47 – Creating Configuration File for Hiding Sensitive Information

1:02:43 – Updating Project Settings File

1:07:01 – Allowing http Traffic

1:07:40 – Restarting the Server & Running the Site

1:08:57 – Fixing Final Bugs

Thank you for such a clean explanation.

Reply

Doltbd Pp

April 29, 2020

Awsome guide, but I keep getting this error:

Target WSGI script '<PATH>' cannot be loaded as Python module.
Exception occurred processing WSGI script '<PATH>'.

Can anyone assist me?

Reply

Alex Holst

April 29, 2020

Hi Corey,

Final stage of my deployment and i get a "404 Not Found" "The requested url / was not found on this server". What am i doing wrong? Minute: 1:08:00

Reply

Marcelo Xavier Marquez Alba

April 29, 2020

Thank you! <3

Reply

Chad Buie

April 29, 2020

Thank you very much for this, Corey, this is a great way to continue to expand yourself. Creating more go to public production instead of local is missing from the Internet and if you do find one it's fully of dependency hell, where things breaks with very little insight.

Reply

Hans G

April 29, 2020

Corey, cheers for this video. I'm quite good with web development (I think) but this part can be a headache. Very very helpful.

I want to learn more about this part of the process. Any good resources you can recommend?

Reply

Hans G

April 29, 2020

Internal Server Error FIX!! Apache Server FIX BELOW:

March 2020 Update: If you're making a new virtual environment, you are probably by default installing python3.7. mod_wsgi is not installing the correct version. Also, linode probably supplying python3.7 on ubuntu machine instead of python3.6.

To fix, follow below:

pip3 uninstall mod_wsgi
mkdir downloads
cd downloads
wget https://files.pythonhosted.org/packages/74/98/812e68f5a1d51e9fe760c26fa2aef32147262a5985c4317329b6580e1ea9/mod_wsgi-4.7.1.tar.gz
tar -zxvf mod_wsgi-4.7.1.tar.gz
cd mod_wsgi-4.7.1
./configure –with-python=/usr/bin/python3.7
LD_RUN_PATH=/usr/local/lib make
sudo make install

Add a new entry to /etc/ld.so.conf

include ld.so.conf.d/*.conf
include /usr/local/lib

then on command line again, run:
ldconfig

Important: be sure you have python3.7 installed in /usr/bin/
To check, run:
ls /usr/bin/ and look for python3.7

If it's missing for some reason, run:
sudo apt-get install python3.7

Reply

Daiane Marcolino

April 29, 2020

This tutorial is just amazing. Thank you for sharing your time with us strangers. I'm just starting with Django and after this I can see many possibilities. You are an amazing teacher.

Edit: I am from Brazil and I am not fluent in English yet. Despite that, I could understand you perfectly. You have a great diction.

Reply

Mengke ZHANG

April 29, 2020

Just a question: I'm encountering 500 internal service errors when loading the page with the ip address. I've looked online, but it tells me this is a general error. Could anyone may be give some tips on this, please? I've followed the video throughout, except that I was running an app of my own. Thanks!

Reply

Bob Russell

April 29, 2020

Help me, all my posts are missing! What happened with my db

Reply

ben villabroza

April 29, 2020

Is this an optimal way of serving media files? Because I did some research and some say that, "[i]n production, uploaded files should be served from a different domain such as Amazon S3." I saw it in this website:

https://djangocentral.com/managing-media-files-in-django/

With that, which method should I opt for because I may have a few thousand images uploaded on my website?

Reply

Etienne Pepin

April 29, 2020

Is that outdated ? i get internal error at the point where i switch from django server to apache2 server. Done 2 times, checker everything 10 times.

Reply

Wai Li

April 29, 2020

Thanks a lot! I followed all the steps, but when I come to testing http://IP:8000 on browser, it waited for a long time and said "This site can’t be reached", the runserver works without error, the port 8000 is listening…so I don't know what is happening and how can I check for the problem, please help~

Reply

Ali A

April 29, 2020

Hi, thanks for your awesome tutorial,
I couldn't find the tutorial of PostgreSQL, can you send me the link?

Reply

Rafael Monroy

April 29, 2020

Hi Corey, best video ever 🙂 so maybe you or anyone can help me. I have an error: https://www.dropbox.com/scl/fi/60ww73u7g6cnldm3ciqhb/Error.log.paper?dl=0&rlkey=qmydmbv8jam9dpuvjpka1qii1
in test mode with python envs works perfectly but with apache a get that error 500, i'm using python3.7

Reply

Abhishek Jain

April 29, 2020

Awesome content with simple explanation for all the topics involved in making any web app alive for public use… Thanks once again to do this series…

Reply

Christopher Batey

April 29, 2020

So how different would this be if you are trying to turn your local (ubuntu) machine a server for your site?

Reply

chabby

April 29, 2020

Its 2020 and this is still the best Tutorial I have found so far! Thank you Corey!

Reply

ronith. NR

April 29, 2020

hey great tutorial

Im getting an error
You don't have permission to access this resource.

apache.error.logs
AH01630: client denied by server configuration: /home/ronith/performace

apache config
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Alias /static /home/ronith/performance/static

<Directory /home/ronith/performance/static>
Require all granted
</Directory>

<Directory /home/ronith/performance/performance>
<Files wsgi.py>

Require all granted
</Files>
</Directory>

WSGIScriptAlias / /home/ronith/performace/performance/wsgi.py
WSGIDaemonProcess django_app python-path=/home/ronith/performance python-home=/home/ronith/performance/venv
WSGIProcessGroup django_app

please help

Reply

Thorsten Gonschior

April 29, 2020

Hey Corey, thanks a lot! I applied this tutorial to my own (now former local..) pythondjangorestframeworkstuff and it worked straight. hired linunx server from local service and followed your instructions and voila 😀 Great Tutorial! I got one issue installing python dependecies packets, didnt work, I had to do it manually. Everything else was working fine.

Reply

Łukasz Wąsowicz

April 29, 2020

Great tutorial series bro! Thanks a lot. I am struggling with one thing: I may access my server (with apache2) via IP address, however typing lixxx-xxx.members.linode.com in my browser brings Bad Request (400). Do you know why is that? Am I suppose to configure sth with linode so that it could work?
If anyone knows the answer, let me know! Thanks.

Reply

Leave a Reply