Learn cPanel

Controlling your Web Hosting Account has never been that easy thanks to cPanel web Control Panel!

• Last Updated: 07/31/2024
• ( 15 minutes reading )

How to Manage Python Applications in cPanel

Introduction

Python is a high-level object-oriented programming language. It is used for back-end and software development, data science, writing system scripts (automation), and not only.

Python is powerful, fast, friendly, and easy to learn. It is also known for its simplicity and readability. Python is used for a wide range of purposes, including data analysis, machine learning, software development, scientific computing, text processing, natural Language Processing (NLP), and many more.

Python's extensive standard library and a vast ecosystem of third-party libraries and packages make it a versatile choice for a wide range of programming tasks, making it one of the most popular programming languages in the world.

This tutorial will cover the “Setup Python App” functionality in cPanel and how you can use it to deploy virtual environments for your Python applications.

 

Getting Started

To use the Python App Selector you should have logged into your cPanel account. For your convenience, we provide you with a direct link to the  How to access the cPanel service

 

Please use the “Search Tools” bar at the top right corner and type in "Setup Python App." Doing so will filter all options and display the functionality under the “Software” category. Please click on it to open the feature. Alternatively, through the main cPanel page, you can find the "Setup Python App" feature under the  "Software" category group.

 

setup-python-app-functionality

 

Please click on the "Setup Python App" feature, and you will be redirected to a new page. Here, you can view a list of existing Python applications for your personal account or create a brand-new one.

 

Creating a new Python app

If no Python web applications have been created yet, you will see the “NO APPLICATIONS FOUNDS” message in the middle of the screen. To create a new one, please click on the “CREATE APPLICATION” button at the top right side of the page.

 

create-python-app-button

 

This action will then redirect you to a new page where you can configure your new Python application. To create a new Python application, you must fill out the settings for your Python application. 

 

Let’s explain the use of these configurations:



  • Python version: Every Python application requires a particular version, so please select the version that best suits your needs from the drop-down menu.
  • Application root: Please use the text field to point to the directory where your application/website files will be stored in your cPanel hosting account. 
  • Application URL: Please use this drop-down menu to select the domain used over the internet to access your website. If you want the website to open on a domain’s sub-directory, please use the text field to type in your desired location.
  • Application startup file (optional: If leaving this field empty, cPanel will add a default passenger_wsgi.py). If you have a simple Python web application that doesn't use a specific web framework, please specify the name of the Python script that serves as your application's entry point. This is the main file that is executed when you run your application. For example: app.py
  • Application Entry point (optional: If leaving this field empty, cPanel will add the default value into the passenger_wsgi.py file). Please use this text field to define the starting point of your application. WSGI stands for "Web Server Gateway Interface". It is used to forward requests from a web server (such as Apache or NGINX) to a backend Python web application or framework. Application Entry point refers to the name of the function/object that the Python environment should use. The value will depend on the application itself (if it is a WSGI, Flask, or Django app) and, in most cases, will be provided in the installation documentation.
  • Environment variables (optional) - Please use this option to add Any environment variables your application needs.


Once ready, please select the “CREATE” button in the top right corner to finalize the process.

 

deploy-python-app

 

Once the application is created, the page will refresh, and at the top of the page, you will be provided with a command that can be used to access the virtual environment on the Terminal via SSH.

 

What is a Virtual Environment, and why do you need to access it?

 

Every cPanel Web Hosting Account exists as an encapsulated entity on the Web Hosting server. As such, every cPanel Web Hosting Account has access to global services like SSH, MySQL, email, and so on by using its binaries. In other words, the server's binaries are globally accessible by every user account. Python is also a binary called "python".

 

As such, there can only be one binary with that name. However, as we have mentioned, you might need multiple Python versions, which the single "python" binary cannot provide. In fact, the "python" binary can only support one Python version - the one that is globally available on the server. 

 

Knowing this, we have found a way to provide support for multiple Python versions using the same "python" binary. This is achieved thanks to the Virtual Environment feature. A Virtual Environment is a method of encapsulation, however, not on the user account level but on an application level. This means that cPanel will create a new virtual environment for every Python application you create.

 

Within every Virtual Environment, cPanel will provide you with a separate "python" binary, meaning that every Virtual Environment utilizes the chosen "python" binary version. Additionally, every virtual environment utilizes different environment variables that you can set. 

 

Typically, to access the binaries of the Web Hosting Server, you will have to log in via the SSH protocol. Accessing the Virtual Environment is no different - you will still have to be logged via the SSH protocol, and you will have to execute a command in order to access the Virtual Environment for the concrete Python application you are managing. The command is different for each Node.js application, and you can obtain it via the application screen in the "Setup Python App" feature of cPanel. 

 

virtual-env-command

 

If you are not familiar with how to use SSH to connect your account with HostArmada via Terminal, please take a look at our tutorials:

How to Manage the SSH access keys for your cPanel web hosting account

How to use SSH keys to connect to your hosting account on Linux and MacOS

How to use SSH keys to connect to your hosting account on Windows 10

Once you enter the virtual environment, you can proceed with further configuration of the application by using the pip command (pip is a package-management system written in Python and is used to install and manage software packages in Python programming language). 

 

terminal-output

 

The screenshot above shows how to enter the newly created virtual environment and the pip command's "help" and "list" parameters.

 

Managing existing Python installations in cPanel

Naturally, the “Setup Python App” functionality will not only allow you to deploy Python apps but also enable you to manage them. This is done by setting up actions that are available within the interface itself. 

Let’s go over them one by one.

 

You can use your existing Python applications' “Stop,” “Restart,” “Edit,” and “Delete” functionalities through the familiar "Setup Python App" interface under the Software” section in cPanel.

 

The aforementioned options are incredibly intuitive and straightforward to use.

 

Stop/Start the Python application

The current status of your application can be found under the “Status” section in the “Web Applications” table section, which includes all your existing Python app installations.

 

start-python-app

 

Please press the “Play” button under the “Actions” column to start a stopped application and vice versa.

 

Restart the Python application

If you want to restart your Python application, please press the “Back twisted arrow” icon under the “Actions” column.

 

refresh-python-app

 

Please note the “Restart” option is not available for stopped applications, and your Python application can only be restarted if it is in “started” status.

 

Edit the Python application

This section can be accessed via the “Pencil” icon under the  “Actions” column. An additional “Configuration files” section will appear with already configured virtual environments, and you can execute the pip install command. Alternatively, you can do so through the Terminal window as described above. You can also add the file from this section with “Environmental variables” (in case one is available).

 

edit-app-env-variables

 

When you finish editing your application, please press the “SAVE” button at the top right corner. All changes will be automatically applied.

 

Delete the Python application

This is a really straightforward process, and, as the name suggests, it will delete the application. Please click on the “Trash bin” icon under the “Actions” column to permanently delete the installation from the corresponding Python application. Please remember to completely delete an application only through this interface instead of manually through the installation directory. 

 

delete-python-app

 

The Python virtual environment is also related to other root folders in the home directory of your account, and removing files manually can damage the virtual environment and affect the following use of the same domain.

Conclusion

That's it. Configuring and using a Python virtual environment through cPanel is not complicated. However, don't forget that our support team is always at your disposal, and you can open a support ticket with us through your account so that we can attempt to assist you if you encounter any difficulties.

...
Nikola Zgurev
Technical Support Captain

Nikola is an accomplished tech-savvy extraordinaire with over six years of experience in the web hosting field. He started as a customer care representative and quickly rose the ranks to become a support supervisor and, eventually - the head of the technical department in HostArmada. His deep understanding of the client's needs, combined with his technical knowledge, makes him the perfect man to create the ideal harmony between client satisfaction and professional problem-solving. You will often find him creating helpful tutorials, articles, and blog posts that help existing customers get around.