How to deploy django app on cpanel

Dominique Megnidro - Dec 13 '23 - - Dev Community

Image description

Deploying a Django Application on Cpanel | Beginner's Guide

Cpanel has become, in the vast world of hosting platforms, one of the widely used solutions by companies to deploy web application solutions. Notable providers include o2switch, Hostinger, LWS, and many others that you can find on the internet. However, it is often observed that Cpanel is particularly optimized for Content Management Systems (CMS) such as WordPress, Joomla, Drupal, and many others.

The task may appear challenging, especially for those who engage in programming from scratch. Despite the plethora of online assistance sites, I personally struggled for over six months to deploy a simple site that performed basic CRUD operations (Create, Read, Update, and Delete) on Cpanel with Django. I assure you, it can be a real frustration, especially when people expect results from you.

Today, I unveil the process for any beginner who does not want to use expensive web hosting solutions for their portfolio, blog, or small e-commerce site by adopting this solution.

What is Cpanel?
Cpanel is a common dashboard for managing web servers. It is highly popular among shared hosting providers. Without Cpanel, technical skills would be necessary for the configuration. However, not all hosting providers use Cpanel.

Configuration
Firstly, to initiate the deployment, you must have your project ready with basic configurations in the settings.py file.

You need to configure the settings for static files.

Image description

urls.py file Configuration

Image description

Pay close attention to the re_path; these are the two paths that will allow you to access the images stored in the database.

Here are the two important configurations you need to make. Ensure that you have created your .environ file to protect your secret keys and to avoid any potential attacks by hackers.

After this step, make sure you have your requirements.txt file.

Next step: Importation of your zip file.

Image description

After this step, move on to your Cpanel dashboard.
• Create your application.

Image description
Image description

• Install the dependencies in the requirements.txt file.

For security reasons, I won't be able to set up the virtual environment.

• Configure the settings.py file for production.

Image description
Image description

passenger_wsgi.py configuration

Image description
You must install the "whitenoise" library to enable your CSS styles to function on the site.

After these steps, the last step is to restart the server or, at least, the application. Once these steps are completed,
Congratulations, we have successfully deployed our site on Cpanel.

You can check your site in the Google search bar, and you're all set.

In conclusion, deploying on cPanel provides a user-friendly and accessible approach to managing your web hosting server. With its intuitive graphical interface, you can efficiently carry out deployments, even without in-depth technical expertise. However, it is always essential to follow security best practices and consider the specific requirements of your project when deploying on cPanel. By leveraging this platform, you simplify the management process and provide an optimal experience for your end users.

Thank you for reading, and see you soon for a new article.

. . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player