Bobcares

Set up Django on the latest Plesk Onyx | How-to

by | Feb 23, 2022

Set up Django on the latest Plesk Onyx with this handy guide from the top experts at Bobcares. 

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Services.

Let’s take a look at how our Support Team is ready to help customers set up Django on the latest Plesk Onyx.

How to set up Django on the latest Plesk Onyx

Our Support Techs have come up with this handy guide to help set up Django on the latest versions of Plesk Onyx. The process involves the following steps:

  1. Install Python
  2. Pre-configure the web server-management
  3. Deploy the web

Step 1: Installing Python

First, we have to check if Python is already present in the system. We can do this by issuing the following command with root server access:

python36 –version

If Python is present, we are likely to see an output similar to the one below:

Python 3.6.6

However, if the command does not yield an output, we can install Python with the help of these commands:

  • Add EPEL repository and then install Python 3.6 with the commands below:
    # yum install -y epel-release
    # yum install -y python36
  • We can also download and then install the Python package manager as seen here:
    # wget https://bootstrap.pypa.io/get-pip.py
    # python36 get-pip.py

Our Support Team would like to point out it is a common practice to ensure there is a separate virtual environment for each Python application. We do this by installing the “virtualenv” package with the following command:

python36 -m pip install virtualenv

After that, we will install Phusion Passenger as we will be using it as an application server for hosting Django projects:

yum update
plesk installer --select-release-current --install-component passenger

Step 2: Pre-configuring the Web Server

  1. In this section, we enable the passenger module by navigating to Apache Web Server Settings under Tools & Settings as seen in the image below:

    Set up Django on the latest Plesk Onyx

  2. Then, head to the Service plan that we are using for domains with Django Apps and enable Proxy mode (in case NGINX is present on the server).
  3. Next, add the following directives in the Web Server tab:
    • PassengerEnabled On
    • PassengerAppType wsgi
    • PassengerStartupFile passenger_wsgi.py
  4. After that, set shell option in the Hosting Parameters tab and save the configuration.

Step 3: Deploying the App

  1. First, the Subscription under Service Plan and navigate to domain’s Document Root:
    cd ~/httpdocs/
  2. Then, move the existing files to the backup directory present in the subscription:
    mkdir ~/backup
    $mv ~/httpdocs/* ~/backup/
  3. Next, make the virtual environment for the App with this command:
    python36 -m virtualenv -p python36 python-app-venv
  4. After that, enter the virtual environment and install the Django framework in addition to checking if we can import it with these commands:
    source ./python-app-venv/bin/activate
    
    pip install Django
    python -c "import django;print(django.get_version())" 
    2.0.3
  5. Then, create a passenger startup file passenger_wsgi.py inside of django-app environment to serve the application through the application server.
    import sys, os
    ApplicationDirectory = 'djangoProject'
    ApplicationName = 'djangoProject'
    VirtualEnvDirectory = 'python-app-venv'
    VirtualEnv = os.path.join(os.getcwd(), VirtualEnvDirectory, 'bin', 'python')
    if sys.executable != VirtualEnv: os.execl(VirtualEnv, VirtualEnv, *sys.argv)
    sys.path.insert(0, os.path.join(os.getcwd(), ApplicationDirectory))
    sys.path.insert(0, os.path.join(os.getcwd(), ApplicationDirectory, ApplicationName))
    sys.path.insert(0, os.path.join(os.getcwd(), VirtualEnvDirectory, 'bin'))
    os.chdir(os.path.join(os.getcwd(), ApplicationDirectory))
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', ApplicationName + '.settings')
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()

    Our Support Engineers would like to point out that we have to replace the variable values in lines 2 and 3 with the corresponding accurate values and then save the file.

  6. Next, create Django project and allow serving requests from any host:
    django-admin startproject djangoProject
    sed -i "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = ['*']/" djangoProject/djangoProject/settings.py
  7. Then, create a tmp directory for application caches and restart the application:
    mkdir tmp
    touch tmp/restart.txt
  8. Finally, change Domain Document Root and we will see the application if the procedure is successful.

[Looking for a solution to another query? We are just a click away.]

Conclusion

In brief, our skilled Support Engineers at Bobcares demonstrated how to set up Django on the latest Plesk Onyx%.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF