how to host a django website on aws

anish jain
4 min readDec 2, 2019

--

first and very important is you must have aws account but that is very easy you just need to sign up and enter your card details as you are a new to aws it gives you free 12 month free tier and believe me guys it is great but be caution their are some service are not free like route53 and service which comes it also has time limits

but service of aws is great i got my bill of INR 350.83 without knowing anything but i just go to support center enter my issue and at moment they call me and resolve my issuse and make my balance 0INR

when i started i am also very scare whether they charge for it.but their is only 2INR for checking and day after it comes believe in me i spend 4 days to host my django website in ubuntu server

using ubuntu gives you more freedom and in depth knowledge

now let do some some work

first create the instance means a compute on aws as i say i choose ubuntu

just next and make it hope so many of you are search because you know how to these simile steps

their is need to connect your aws instance to your computer we show use git to connect you may use putty or other. for connection you have to create .pem file to do and see practical demo see this vedio.

just see where the is connection is done and now lets start with some commands

just make allowed host =[*] so every ip can access it

installing some dependencies guys do as i and you website is live i am sure

now when you see the video you see your instance in git bash login with root user by sudo -i command you see user change to root thats great

commands

  1. apt update
  2. apt install apache2 #click y when ask
  3. ufw allow in “Apache Full”
  4. now for test copy the ip and past in browser you can see apache server page if not their must me some error
  5. now install python pip as python comes pre install
  6. apt install python3-pip
  7. apt install libapache2-mod-wsgi-py3
  8. now go to www directory by command
  9. cd /var/www
  10. in this directory you have either put django website folder from git hub or just make it hope so you know this ex djangomac
  11. now cd into django directory and install virtual environment by commad
  12. pip3 install virtualenv
  13. virtualenv “ here name of virtual env like i am using myenv”
  14. to active it write
  15. source djangomac/bin/activate
  16. to install django command is
  17. pip3 install django

change setting.py add these line at bottom as show in image

now run some django commands line

python manage.py makemigration,

python manage.py migrate

python manage.py createsuperuser

python manage.py collectstatic

hope so everyone here know what is django basic commands

for test just write python manage.py runserver 0.0.0.0:8000

and now copy ip:8000 and past you see website is running as port 8000

but may be error comes or page not found comes guys this is due aws security group setting

guys you can see above mention vedio if any thing you can’t understand just know the basic of aws and new security group as mention is vedio for 8000 port

but here website is still serve by django development server which is not for production so that’s why we use apache server now deactivate django server

now go to

cd /etc/apache2/sites-available/

nano 000-default .conf

#documentRoot /var/www/html

Alias /static /var/www/prodroomin/aws_room/static
<Directory /var/www/prodroomin/aws_room/static>
Require all granted
</Directory>

<Directory /var/www/prodroomin/aws_room/roomv1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIDaemonProcess myenv python-path=/var/www/prodroomin/aws_room python-home=/var/www/prodroomin/aws_room/myenv
WSGIProcessGroup myenv
WSGIScriptAlias / /var/www/prodroomin/aws_room/roomv1/wsgi.py

error logs

just be very careful with name of directory you use and name of virtualenv

now save the scripts you can see how to use nano and save

now in terminal write

a2dissite 000-default.conf

a2ensite 000-default.conf

service apache2 restart

now again go to cd /var/www directoty

and give some permission to out directory

chmod 664 “path of db.sqlite3”

chown :www-data “path of db.sqlite3”

chown :www-data “your directory name where you make django app”

guys be very careful with path name and directory name

error comes definitely but common we are developers remember things always take time to learn you cant ‘t learn the things in one day. day by day make learn somethings atlast you know everythig

guys these reads these types of quotes and positive news visit my site

https://optimis.ml/

thank you so much but i know i am not able to convey everything may this is my first blog if you dont’t understand mail me at helloanishjain@gmail.com

--

--

anish jain
anish jain

Written by anish jain

like to create things,and some time to break them to get indepth knowledge,stronly believe in learning never exhaust the mind

No responses yet