5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
BLEARNINGCLUB
python Django web development programming tutorial and technical blogs
blearningclub.com Printed on May 23, 2021
DEPLOY YOUR DJANGO PROJECT ON
DIGITALOCEAN
August 28, 2020
Categories: blog
Tags: Django on digital ocean
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 1/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
DJANGO WITH APACHE AND MOD_WSGI ON UBUNTU
Digital Ocean provide you a vps server. There you can create your droplet . Droplet means a computer or cpu or a machine . And
put a root password and choose a data center and choose Ubuntu and create the droplet.Wait some times and it will create a
Droplet for you.
How to deploy your Django project with DigitalOcean
https://youtube.com/watch?v=QQ_hNDKIbxY
CONSOLE AND ALLOW OPEN SSH
After create the droplet then Open the console ( click on right side on your droplet ). Then you have to login with root and root
password (which you have enter for create droplet ).
Login : root
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 2/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
password: enter your root password
Now check the rewall status
ufw status
You have to enable it. Type the command below on your cmd
ufw enable
now you have to allow OpenSSH . Type the command on your cmd
ufw allow OpenSSH
Now close the console And open command prompt or terminal in your computer
NOW FOLLOW THE STEPS TO RUN DJANGO
After open Command prompt or terminal in your computer then type the below command and login with username is root and
password is your root’s password
ssh root@ip_adress
IP address is provided by digital ocean
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 3/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
FOLLOW THE STEPS FOR PYTHON 3 OR LATEST VERSION
Now you have to update your app rst. so type the below command :
sudo apt-get update
Now wait sometimes and now you have to install python 3 apache2 libapache2-mod-wsgi-py3 . So type the below command :
sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
Now you have to install virtual environment for python 3 . So type the following command :
sudo pip3 install virtualenv
Now create a directory for your project ( here directory name is myproject )
mkdir ~/myproject
cd ~/myproject
Now you are inside is in myproject . here create a python environment for your project :
virtualenv projectenv
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 4/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
Now you have to activate the environment:
source projectenv/bin/activate
Now install Django :
(projectenv) $ pip install django
UPLOAD YOUR DJANGO PROJECT VIA FTP FILE MANAGER
Install the FTP le manager ( File zilla ) from google and open it then you have to put host username and password and port .
host: your ip adress or domain
username: root
password: root password
port : 22
Now after successfully connected go to myproject ( go to directory of your python env ) . And just upload your django project ( you
can drag and drop from your computer )
EDIT PROJECT SETTINGS
go to settings.py in your django project and allowed host or ip adress . Then you have to set a static directory and Static root
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 5/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
ALLOWED_HOSTS =
. . .
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
Now you can migrate your database and create a superuser .But migrate your database is recommended just type : python
manage.py migrate
And now go to the directory of manage.py and Just type:
(projectenv) $ python manage.py collectstatic
Now you can run with local host . But at rst you have to allow the 8000 port :
(projectenv) $ sudo ufw allow 8000
(projectenv) $ python manage.py runserver 0.0.0.0:8000
Now deactivate the environment . because here we will run django by apache
(projectenv) $ deactivate
CONFIGURE APACHE SERVER
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 6/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
Now that your Django project is working, we can con gure Apache as a front end.Now you have to edit con guration for Apache
server . At rst go to sites available in Apache 2 folder and you have to edit 000-default.conf le :
sudo vim /etc/apache2/sites-available/000-default.conf
Or You can use File zilla ( FTP Fie manager ) and edit 000-default.conf . Add this code and commet out the document root at rst (
recommended) :
Alias /static /..static directory.../static
<Directory /....static directory....../static>
Require all granted
</Directory>
<Directory /...directory of wsgi.py ...../myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/.... directory of python env....../myprojectenv python-path=/....
directory of manage.py .../
WSGIProcessGroup myproject
WSGIScriptAlias / /.... directory of wsgi file ..../wsgi.py
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 7/8
5/23/2021 DEPLOY YOUR DJANGO PROJECT ON DIGITALOCEAN – python Django web development tutorial | Blearningclub
NOW ALLOW APACHE FULL AND YOUR PROJECT AND DATABASE
Now you have to add some rule :
chmod 664 ~/myproject/db.sqlite3
sudo chown :www-data ~/myproject/db.sqlite3
sudo ufw allow 'Apache Full'
Now you can check syntax error by following command :
sudo apache2ctl configtest
Now restart the Apache server by following command :
sudo systemctl restart apache2
Or For restart the server you can type ( Optional ):
sudo service apache2 restart
Now you can run your Django project successfully . And also you can add a custom domain
https://blearningclub.com/?print-my-blog=1&post-type=post&statuses%5B0%5D=publish&rendering_wait=0&columns=1&font_size=normal&image_size=medium&links=include&show_site_title=1&show… 8/8