We have uploaded our project in the last part of tutorial. We’ll now create virtual environment and use the requirements.txt for installation of package. Finally we will have our project LIVE after few more configurations.
Log on to the VPS using terminal before proceeding.
Create Virtual Environment
First let’s install
virtualenv package in our server.
virtualenv is a tool to create isolated Python environments.
$ pip3 install virtualenv
We’ll create virtual environment inside the virtual host folder(/usr/local/lsws/social here). Run following command:
$ virtualenv /usr/local/lsws/social
And activate the environment using :
$ source /usr/local/lsws/social/bin/activate
Check if python loaded from virtual environment
$ which python
Install Packages from requirements.txt
Navigate to root directory of the project
$ cd /usr/local/lsws/social/public
Now we’ll install all the packages in the requirements.txt file. Run this command in terminal.
$ pip3 install -r requirements.txt
Finally we need to install psycopg2 library as adaptor between Python and Postgesql Database.
$ pip3 install psycopg2
We are almost finished the setup part and our site will be Live soon. Now lets edit the Context configuration. Open the Web Admin Panel in browser and Navigate to Virtual Hosts > “Your Virtual Host” > Context > “Your context” . Click on “pen” icon to edit the configuration.
We had set the Startup File to “wsgi.py”. Change it to point the location of wsgi.py file of Django project. wsgi.py file is located in same folder as settings.py by default. This path is relative to application root directory. Also in Environment we’ll add some variables like PYTHONPATH for setting up with virtual environment.
Startup File :
Collect static files
$ python manage.py collectstatic
And the Final step, Create admin super user
$ python manage.py migrate $ python manage.py createsuperuser
Great! you are all set up and your site is already LIVE. Visit http://YOUR_DOMAIN in the browser