How to Deploy a Python Django Application on Hostinger VPS with CloudPanel (Example: deplow)

How to Deploy a Python Django Application on Hostinger VPS with CloudPanel (Example: deplow)

If you’re looking to deploy a Python Django application on a Hostinger VPS with CloudPanel, this guide will walk you through the entire process using deplow as an example application. CloudPanel makes server management easier, and this method ensures that your Django application runs smoothly with proper configuration.

Prerequisites

Before we start, ensure you have the following:

  • A Hostinger VPS with CloudPanel installed.
  • Python 3.x installed on the server.
  • A domain configured (e.g., py.uplesk.com).
  • A working Django application (we’ll use deplow as an example).
  • SSH access to your VPS server.

Step 1: Setting Up CloudPanel

CloudPanel is an easy-to-use server management panel for VPS hosting that can handle multiple applications, including Python-based ones like Django.

Once your CloudPanel is installed on your Hostinger VPS, follow these steps:

  1. Log into CloudPanel: Open your browser and access CloudPanel using your server’s IP address (or domain) and port :8443. It will look something like: http://your-server-ip:8443.
  2. Create a New Application: In the CloudPanel dashboard, click on “Create Application”. Select Python as the application type. Set a domain for your app (e.g., py.uplesk.com) and assign a document root. This is where your Django project will reside.
  3. Configure the Application: CloudPanel will automatically set up the environment for running your Python app. But, you may still need to perform additional steps, such as installing dependencies.

Step 2: Install Dependencies on the Server

Now that CloudPanel has created the Python environment, you need to install the necessary dependencies:

  1. SSH into Your VPS: Log in to your VPS via SSH:
    ssh root@your-server-ip
  2. Install Virtualenv (if not already installed):
    sudo apt install python3-venv
  3. Create a Virtual Environment for Django:
    cd /home/cloudpanel/your-app-folder  # navigate to your application directory
    python3 -m venv venv
    source venv/bin/activate
  4. Install Django and Gunicorn:
    pip install django gunicorn

Step 3: Set Up Your Django Application

Now, either clone your Django project or create a new one:

django-admin startproject deplow

Navigate to your Django project directory:

cd deplow

In settings.py, ensure the ALLOWED_HOSTS include your domain:

ALLOWED_HOSTS = ['127.0.0.1', 'py.uplesk.com']

Step 4: Configure Gunicorn to Serve Django

Test Gunicorn with the following command to ensure it works:

gunicorn --bind 127.0.0.1:8000 deplow.wsgi

Once confirmed that Gunicorn is running, you can run it in the background using:

nohup gunicorn --bind 127.0.0.1:8000 deplow.wsgi &

Step 5: Configure Nginx as a Reverse Proxy with CloudPanel

With CloudPanel, Nginx is automatically configured as the reverse proxy for your application. However, you may need to ensure that it’s configured to forward requests from the public domain to the local Gunicorn server.

  1. Log into CloudPanel and go to your application.
  2. Configure Nginx: CloudPanel will have a default Nginx configuration for your application, but you may need to confirm that it includes the following in the proxy settings:
    server {
        listen 80;
        server_name py.uplesk.com;
    
        location / {
            proxy_pass http://127.0.0.1:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
    

Step 6: Restart Nginx and Apply Changes

  1. Restart Nginx to apply the changes:
    sudo systemctl restart nginx
  2. Ensure that Nginx is correctly forwarding traffic to Gunicorn by accessing py.uplesk.com in a browser.

Step 7: Set Up Domain Name and DNS

Make sure the DNS settings of py.uplesk.com point to your VPS IP address. You can configure DNS through your domain registrar.

  1. Log in to your domain registrar’s control panel.
  2. Set the A record for py.uplesk.com to point to the IP address of your VPS.

Step 8: Monitor Gunicorn with Systemd (Optional)

You may want Gunicorn to run as a service and restart automatically if the server reboots. To do this, create a systemd service file for Gunicorn:

  1. Create the Gunicorn service file:
    sudo nano /etc/systemd/system/gunicorn.service
  2. Add the following configuration to the file:
    [Unit]
    Description=Gunicorn instance to serve deplow
    After=network.target
    
    [Service]
    User=root
    Group=www-data
    WorkingDirectory=/home/cloudpanel/your-app-folder/deplow
    ExecStart=/home/cloudpanel/your-app-folder/venv/bin/gunicorn --workers 3 --bind unix:/home/cloudpanel/your-app-folder/gunicorn.sock deplow.wsgi:application
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable and start the service:
    sudo systemctl enable gunicorn
    sudo systemctl start gunicorn

Step 9: Final Test

After completing all steps, visit http://py.uplesk.com in your browser. If everything is set up correctly, your Django application deplow should be up and running.

Conclusion

In this blog post, we’ve covered the process of deploying a Python Django application on Hostinger VPS with CloudPanel, using deplow as an example. With CloudPanel’s user-friendly interface, the deployment process is simplified, and you can ensure your Django application runs efficiently. By following the steps above, your app will be accessible via your domain, py.uplesk.com, and ready for production!

 

Share with others:

Inspirations given with reviews

Our most loved clients give us feedback about our work
Hannah
NY, USA
Read More
Based on Creative & Best Seo Agency London they did Phenomenal job. I needed to have my design files transferred over to be print ready within 1-2 days. There were a few revisions I needed and he handled them phenomenally and got them to me so fast. Thank you so much! I’ll only use him for future file formatting.
Mobiuz Film
LONDON, UK
Read More
Stunning packaging and t-shirt design with the cutest panda artwork! Impressed by the creativity and top-notch service. Highly recommend!" 🐼🎨
Anna-Marie Wayne
London, UK
Read More
Wows Best Seo Agency London or I can say Best Seo agency uk with animal-themed magic! His creativity and professionalism create captivating packaging. Highly recommend! 🐾🎁
Nitisha Majithia
London, UK
Read More
Wow, wow, wow!!!!!!!! Great communication, created exactly what we wanted with little instruction, very impressed by final result. Absolutely love my design. 100% worth it. I highly recommend using this seller service!
Lauren Vaknine
London, UK
Read More
We have used a few producers for the Reconditioned podcast now, and Uplesk has been the one to not only create the highest quality work (both in audio and video editing)
Aman ilakin
NY, USA
Read More
Great work, Team Uplesk did creative ideas to see what i would like and then we modified a couple to get what you wanted exactly. Would recommend and i would definitely be back!
Sean Russel
NY, USA
Read More
"Thank you so much. Really love to working with your Team again. You are very much helpful person."
KEY OUTREACH
NY, USA
Read More
"Team Uplesk did some good work on my website and I will be using him again soon good communication skills."
Paul Buchheit
NY, USA
Read More
Great extension of our web project was implemented and finished before delivery time - great work - looking forward to the next project :)
Mike Cassidy
NY, USA
Read More
Salauddin from Team Uplesk been an exceptional project manager who provided invaluable consultation for my new NGO's project. His expertise and guidance in seeking funds for the welfare of homeless people were highly commendable. I am truly grateful for his insightful advice, which has significantly contributed to the success of my project. I highly recommend!

Have a big project??

To complete big and short project based on subscriptions or one time payment feel free to schedule a short meeting with us.

Still not sure?

Feel free to message us

Subscribe to our newsletter

Optimized by Optimole

Get Expert Business Solution Tips & Exclusive Offers