How to deploy Django Application in cPanel?
So you are a Python developer who doesn’t know how to deploy Django Applications on cPanel? Well, this guide is all you need for an easier deployment. This detailed step-wise guide starts with the basics for a smooth Django application deployment. Deploying a Django application using cPanel is a must-have skill for all web developers. So, lets learn how:
Before we start the deployment process, here’s a small checklist for a smooth installation process.
- A Django application/project ready for deployment.
- A well-set-up domain name
- A code editor like Visual Studio Code
- Basic Knowledge of Python and Django
- Access to your cPanel credentials
- FTP client (if you decide to file transfer using FTP client)
Log in to your cPanel account with your credentials. Navigate to the “Setup Python App” section and click the “Create Application” button.
Now configure your Python application as
- Log into your cPanel account.
2. Navigate to the “Software” section and click the Setup Python App feature.
3. Click the “Create Application” button
4. Configure your Python application:
-
- Select your Python version (recommended: Python 3.8 or higher)
- Specify the Application root folder name
- Enter your Application hostname (URL)
- Click “Create.”
5. Open the provided URL to verify the initial setup.(Blue open text beside the Application URL section)
6. You should see a success message displayed that signals Python is configured in your cPanel
Locate the virtual environment code in your Python application and copy it.
- Open the terminal in your cPanel
- Paste the activation code and press Enter
- Run
pip install django
in the terminal.
- Run
django-admin start project project
in the terminal
Now, to verify the installation, follow these steps:
- Navigate to File Manager and then to a folder named “virtualenv”
- Open the virtual folder and look for your python version. In my case, Python version 3.8 is displayed.
- Inside the “bin” folder, you can find all the required dependencies installed.
You have successfully installed the Python Django framework on your c-panel.
It’s now time to prepare your application for deployment.
- Open your Django project in the code editor, preferably Visual Studio Code.
- Navigate to the root directory
- Run pip freeze>requirements.txt (This creates a requirement.txt file inside the Django application
- Open the requirements.txt file to see all your project dependencies here.
- Now, create a zip file of your project
Necessary: Do not include the env folder
- Go to cPanel File Manager
- Navigate to your application root folder
- Upload your ZIP file here
- Extract the ZIP file in the same folder
- Now, open the passenger_wsgi.py file
- You can make changes to the passenger_wsgi.py file depending on your paths and project name.
Configure your Django Settings by adding your hostname and root files.
- Open your project and navigate to the settings.py file
- Edit this file to add your hostname to ALLOWED HOST and root for static/media files.
- You can also update the database configurations if needed
Installing dependencies is the final step to deploy your Django application
- Return back to the cPanel terminal
- Activate the virtual environment copying the code snippet and running it in the terminal
- Run:
pip install -r requirements.txt
- Once your dependencies are successfully installed, run
python manage.py collectstatic
- Answer “yes” when prompted
- Go back to the Python App section in cPanel
- Click “Restart Application”
- Visit your application URL
- Congratulations! Your Django application should now be live
- Check application logs in cPanel
- Verify that all passenger_wsgi.py settings are as needed
- Confirm all dependencies required are installed
- Check Python version compatibility
- Look for path configuration issues
- Verify static file configuration
- Run collect static again
- Check file permissions
- Confirm static file path
- Review database credentials
- Check database configuration
- Ensure the database is running
- Verify migration status
- Keep DEBUG mode off in production
- Use strong passwords
- Install SSL certificate
- Regular security updates
- Protect sensitive files
Maintenance Tasks
- Regular database backups
- Monitor error logs
- Update dependencies
- Document changes you make
- Regular performance checks
- Enable caching
- Optimize database
- Compress static files
- Monitor resources
- Regular cleanup
- Document your deployment process for future reference
- Set up monitoring for your application performance
- Keep dependencies updated
- Check logs regularly
- Test thoroughly before deploying
- Use version control
- Monitor server resources
This guide provides everything needed to deploy your Django application on cPanel. Before going live with your production deployment, remember to test in a staging environment.