Deploy django on ubuntu vps | Deploy python django on server | Make live your python app In ubuntu server | django on server

K. Behera
3 min readMar 28, 2021

Hey everyone Let’s start with to be continued topic here that how we can deploy python django apps in ubuntu vps..

So let’s start

So before that if you dont know how to setup a ubuntu server please click here to check out..

So after setting up server now the time to setup django on ubuntu. Before that let’s recall what we have done.

We have installed apache, php, mysql, python and pip too..👍

Great..

Now the time is to install django.

So for that we can simply move on to a location that is

cd /var/www

Then let’s create a folder for storing our project file.

sudo mkdir djangoproject

Install virtual environments using pip3 and activate it.

sudo pip3 install virtualenv

virtualenv djangoproj

source djangoproj/bin/activate

Then create a Django project inside virtualenv

django-admin startproject djangoproj .

I have given “.” here that all the files will be extracted there only otherwise it will create a new folder again with the same name.

Now you can see some of the files will be created automatically and that is the specialty of django framework if you wanted to know more about framework click here

Ok so now to time is to run and test our project is it running fine.

so give command ls and you can see “manage.py” otherwise go to the project folder you will find manage.py

now give the command

python manage.py runserver

And BOOM.. now you can see your django server has been started. but how you can see your django server for that just stop the server by clicking “ ctrl-c”

Then go to settings.py that also will be inside your project folder using cd command.

open settings.py using command.

sudo nano settings.py

And search for “allowed_hosts = []”

Now you have to enter your ip address inside that square braces like this

Allowed_Hosts= [“192.168.0.0”]

Thats it…

Now save and come back using command….

give “Ctrl-x” then press “y” and “ enter
” and come back to the folder where manage.py will be.

And again start your server using the command

python manage.py runserver 0.0.0.0:8080

Now you can check your Django welcome screen in your browser by entering your server ip address and followed by “:8080” ex: — 192.168.0.0:8080

I believe you are good at till this point.

So lets move on to the server configuration.

give the command to change some configuration on server

sudo nano /etc/apache2/sites-available/000-default.conf

Now you can see there nano editor has been opened and you have to modify that.

Please have a look this conf file and change your .conf file according to it.

please make your indentation perfect as here indentation is not proper.

After that disable your already running site and again enable it.

By giving command.

sudo a2dissite 000-default.conf

then: -

sudo a2ensite 000-default.conf

And finally restart apache

sudo service apache2 restart

Now if you have done all these things properly you can check your running on your public ip address.

or else please check it again.

And now your time is to migrate your existing django application to your server django project.

Now you can find your application to be run in your server.

click here for check out python framework

Click here for how to setup a ubuntu server

Click here to know more details about server and types of server.

Thank you everyone 🙏

khirod-blog.blogspot.com

--

--