Deploy Django on Shared Hosting cPanel: In below article, I represent you a step-by-step technique to deploy a Django project on ‘shared hosting cPanel’.
One of the advantages of the Django project is that it is highly affordable.
But the disadvantage comes at accessing SSH root access, which by the way is not granted in Shared Hosting.
Best you can do is calling Python modules via pip. However, some modules may not function correctly.
The basic site and blogs work awesome via Django. However, utilizing the pip command, you can easily manage advanced websites.
Be it the readymade framework, Python’s architecture, or the lovely Django community, laying hands on a Best Django Hosting is beneficial for any enthusiastic web developer.
Django is filled with shortcuts to form Web developers’ lives easier, but all those tools are of no use if you can’t easily deploy your sites. Since Django’s inception, simple deployment has been a serious goal.
There are many options for deploying your Django application, supported your architecture or your particular business needs, but that discussion is outside the scope of what Django can offer you as guidance.
I have the Shared YouElite Plan of the YouStable Shared Hosting which I will be using in this post.
The basic YouElite plan provides you MySQL databases using which you can use the version 3.8.6 of Django because we will be using the pymysql module command for the database
drivers and the driver provided by pymysql works until Django 3.8. 6 you can also use the latest version of Django as per your choice.
Deploy Django on Shared Hosting | Create a Python App
- Log in to cPanel and open Setup Python App.
- Now click on Create Application
- Select Python Version 3.8.6
- Application Root is the directory where you will place the code files of your Django project. Make sure that it is a different folder than your domain root.
- “Application URL” is the domain or subdomain where your app will run
- In the “Application Startup File”, type passenger_wsgi.py
- In the “Application Entry Point“, type application
- The “Passenger log file” is the file where logs will be stored. Set a file for this so that we can see the logs later if there is an error.
- After setting all these, click on the Create button.
Setup the Database
Now Open “MySQL Databases” in cPanel.
Create a “new Database” and note the database name. We will need it “later”.
Create a new MySQL user and note the username and password. We will need it later.
Add the “New user” to the new Database.
Grant all the “permissions” to the user and select Make Changes.
Upload your Django project
- Open your cPanel
- Click on “File manager” Under Files and Go to “Application root” you mention previously.
Now Extract the ZIP File of your Prject.
Your project files should be in the Similar folder as the passenger_wsgi.py file in Deploy Django in Shared Hosting. Make assured that manage.py and passenger_wsgi.py are in the same folder.
Now, Edit the “Passenger_wsgi.py” file.
The Base is your Project Folder name
Add the following code to the file:
from base.wsgi import application
Where the base is your project folder. it’s an equivalent folder that contains your settings.py file. it’ll vary if you’re not using the test project that I provided. you’ll locate your wsgi.py file and import application from it.
Now edit your settings.py
Add your domain to the ALLOWED_HOSTS list. If there is a www version of your domain, add that too. Do not use http:// to https://
Now go to the end of the file, modify STATIC_URL and change the STATIC_ROOT
Now edit the __init__.py file
Add the following code
Copy the Following code and paste it in __init__.py
Complete configuration from the Terminal
Open the Terminal in your CPanel. If you can not find the terminal, go to Manage Shell and Enable SSH Access. You can also do these steps using SSH but using the terminal is easy.
Copy the command to enter the virtual environment from your python app.
Paste your Code here-
Install Django “According to your Python Version” by running the following command.
pip install django==3.1.4
pymysql is required for using the MySQL database. Install it using pip. Here you will install any other modules required by your Django app.
pip install pymysql
If your migrations are not complete, then make migrations.
python manage.py makemigrationsCopied!
Run migrate to create tables in the database.
python manage.py migrate
Run collectstatic to move the static files to the static root folder specified in settings.
python manage.py collectstatic
Run createsuperuser to ass a user to the Django admin panel
python manage.py createsuperuser
Finally, All Done 😊.
restart the “python app”.
Your Django app is Installed Successfully.
Now enjoy your Project 🥰.
Where can I host Django for free?
For Free you can go for GoogieHost, Pythonanywhere, or Heroku. You can also set up a fully functional web server within a coupon.
How do I deploy a Django project?
Follow the steps Above and Install your Django App Easily, If feel any Mistake Comment in Comment section.
Is Django Fronted or backend?
First of all let me tll you Django is Framework, you Can Use Easily for both backend and frontend.
Hope the hole above Tutorial of Deploy Django on Shared cPanel Hosting helped you.
If you got any error while Installing and Deploying django in Shared hosting, please comment in the comment section.
If you Foud this Article helpful or have any suggestions about it, let us know in Comment section.
Happy Django Deployment in Shared Hosting🥰.