How To Deploy Django With Apache web-server on VPS-Ubuntu
Django is a python framework used to build web applications. In this guide, we will learn how to deploy Django application on a VPS running on apache web-server on ubuntu-18.04. Install required Libraries Access your VPS on ssh ssh root@yourip #then key in your password on prompt sudo apt-get updat
Django is a python framework used to build web applications. In this guide, we will learn how to deploy Django application on a VPS running on apache web-server on ubuntu-18.04.
Install required Libraries
Access your VPS on ssh
ssh root@yourip #then key in your password on prompt
sudo apt-get update
sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
#this will update the ubuntu os on the vps and install apache2 webserver , pip3- which is the python package manager, and mod_wsgi a module for integrating Django and the apache webserver.
Set Up the Django virtual environment
sudo pip3 install virtualenv
Navigate to the location where you want to set up your project. In our guide, we will set up the project on the home directory
cd /home #navigate to the home directory
mkdir test_django #create a folder for your app
cd test_django #navigate to the root folder of your application
create and activate the virtual environment
virtualenv env #create a virtual environment with the name env
source env/bin/activate #activate your virtual environment. This helps in ensuring that only dependencies downloaded for this application will only be applicable to this application. In case you have multiple Django applications, you can run them with different versions of dependencies.
On activating the env, your command line should change
(env) root@username:/home/test_django#
pip3 install django
Resolving Permissions Issues Update some file permissions to avoid file permission related errors. Run the following commands. Sqlite3 related commands only applies if sqlite3 is the default database. Skip the first 2 lines in case you will use any other database. See mysql database confirguration below.
sudo chmod 664 /home/test_django/db.sqlite3
sudo chown :www-data /home/test_django/db.sqlite3
sudo chown :www-data /home/test_django
Do a test to ensure all the configurations are Ok. Should there be an error, check and adjust according. Most common errors are path related.
sudo apache2ctl configtest #If the response is OK: everything is working as expected.
MYsql Database configuration
Was this article helpful?