Step-by-Step: Building a Python Application on cPanel Hosting

Step by Step Building a Python Application on cPanel Hosting

Python is an easy-to-use, high-level programming language that many people love. It’s great for backend development, data science, and automating tasks. Python is powerful, fast, and user-friendly. It’s effective in data analysis, machine learning, and software development. Thanks to its extensive standard library and a wealth of third-party tools, Python offers incredible flexibility for numerous programming tasks. It’s one of the most beloved programming languages.

Just scroll down to the bottom, and you’ll discover some helpful insights on building a Python application on cPanel hosting.

Log in to cPanel

First things first, you need to go to the cPanel of the website and access cPanel via Client Area:

  • You should have received access upon signing up for a service.
  • Log in to the Client Area with your credentials to start the procedure.

Once logged in:

  • You will land on the “Dashboard” page.
  • Several sections will show information about your services.

Focus on the “MY SERVICES” section:

  • Located around the middle of the page.
  • Displays all Web Hosting Services you have with the provider.

Service Details:

It may vary from one service to many. The general information provided includes:

  • Server name
  • Service status
  • Type of service
  • Associated domain
  • Billing cycle
  • Next due date
  • A row of useful links

To access cPanel:

  • Click on the small “cP” icon.

Setting up a Python app

Setting up a Python app

Read about how to set up the Python app:

  • Why not try the “Search Tools” bar in the top right corner? Simply type in “Setup Python App,” and you’ll find all the options conveniently filtered. This makes it super easy to discover the functionality you need in the “Software” category.
  • Click it to open the feature. You can easily find “Setup Python App” in the “Software” category on the main cPanel page.
  • Just click on the “Setup Python App” feature to smoothly navigate to a new page. Once you’re there, you’ll have the chance to explore your account’s existing Python applications or even create an exciting new one.

If you still need dedicated servers, contact OffshoreServers.NET. We’ll be more than happy to provide you with the best hosting solutions!

Creating a new Python app

If you haven’t had a chance to create any Python web applications yet, you’ll see the message “NO APPLICATIONS FOUND” pop up in the center of your screen. To kick off the creation of a new application, just click on the “CREATE APPLICATION” button in the top right corner of the page. This will guide you to a new page where you can set up your Python application. Don’t forget to fill out all the necessary settings to begin your journey. 

Let’s explain the use of these configurations:

  • Python version: Every Python app has a unique version, so you can easily choose the one that best suits your needs from the drop-down menu.
  • Application Root: In the text field provided, please share the directory in your cPanel hosting account where you’d like to store your application or website. This will help us ensure everything is set up in just the right files. This location is crucial for organizing your projects and ensuring they function correctly. Properly designating your application root aids in file management and access, making your development process more efficient. Thank you for taking the time to thoughtfully set this up.
  • Application URL: Please use this drop-down menu to choose the domain you’d like to use to access your website. If you prefer the website to open in a specific domain’s subdirectory, enter your desired location in the text field provided.
  • Application startup file: If you have a straightforward Python web application that doesn’t rely on a specific web framework, we would love for you to share the name of the Python script that acts as your application’s entry point. This is the main file executed when you run your application. For example: py
  • Application Entry point: Fill out this field to start your application. Did you know that WSGI stands for “Web Server Gateway Interface”? It is crucial to forward requests from a web server, like Apache or NGINX, to your backend Python web application or framework. The application entry point is the function or object name in your Python environment to use. This is where your program begins, setting the stage for everything that follows. This value varies depending on your application, whether it’s a WSGI, Flask, or Django app, and is usually provided during installation documentation.
  • Environment variables (optional): We encourage you to use this option to include any environment variables your application might find helpful.

When you’re all set, click the “CREATE” button in the top right corner to wrap things up.

After creating the application, the page will refresh, and you’ll see a command at the top that you can use to access the virtual environment on the Terminal through SSH.

Test the application

Test the application

Once you’ve installed the application, it’s a great idea to check that it’s running smoothly.

  1. Execute the following command: 
    python pythonapp.py 
    The output may look like this example:

1

2

3

4

5

6

7

8

9

<.DOCTYPE html>

        …

          <section class=”main”>

            <h1>Hello world.</h1>

            Welcome to the example app.

          </section>

        </body>

        </html>

  1. Why not open another terminal window and log in to the server using SSH with the same cPanel user? It’ll be a smooth process.
  2. Run the following command:
    curl http://localhost:5000
  3. The output will resemble the following example:
    Hello, World.

Register the application

Once you’ve installed the application, the next step is to register it. Simply head over to cPanel’s Application Manager interface (cPanel » Home » Software » Application Manager). After that, you’ll be able to access the application in your web browser using the following URL: http://example.com/pythonapp

Restart the application

After editing your application, you need to restart it by creating a text file named restart.txt. Place this file in the application’s/tmp directory. This file tells Phusion Passenger® to restart the application, ensuring your modifications take effect.

Important:

Phusion Passenger will only restart your app when you touch the restart.txt file.

FAQs

Read about the FAQs that will help you with this guide:

Do all cPanel hosting providers support Python applications?

Not all cPanel hosting plans support Python. You’ll need a plan with Python support and access to features like “Setup Python App” or SSH. Check with your hosting provider before getting started. At OffshoreServers.NET, we’re excited to offer you top-notch hosting solutions and dedicated streaming servers alongside friendly customer support, all complemented by an advanced control panel to enhance your experience.

How can I access the Python App setup in cPanel?

You can find it under the “Software” section in cPanel or by typing “Setup Python App” in the search bar. Click on it to create or manage your Python applications.

What is the purpose of the WSGI file in my Python application?

The WSGI file (e.g., passenger_wsgi.py) connects your Python app to the web server. It defines how your Python code handles incoming web requests, making it essential for app deployment.

What does the ‘Application Entry Point’ refer to?

It’s the name of the function or object that serves as the entry point for your Python app. This might be an application for WSGI apps, while Flask apps might use an app.

Can I install third-party Python packages on cPanel?

Yes. After creating your Python app, activate the virtual environment via SSH and use pip install or pip install -r requirements.txt to install your packages.

How can I check if my Python app is functioning?

Run the app in the terminal with a command like python pythonapp.py, or test it with curl http://localhost:5000. You should see an HTML output or a “Hello, World.” response.

How do I apply changes to my app after editing it?

To restart your Python app and apply changes, create a restart.txt file inside the /tmp directory of your application. This signals the Phusion Passenger to reload the app.

Final Thoughts

This step-by-step guide is perfect for building a Python application on cPanel hosting. When you’re ready to dive in, just follow all the instructions closely; they’ll help you successfully execute your project. We’re confident these instructions will make it a breeze for you to build your Python app yourself. Make sure that you don’t miss out on any step.

If you’re thinking about building Python applications on a cPanel hosting but feel unsure about where to find the right hosting, there’s no need to worry. OffshoreServers.NET is here to offer you the best offshore storage servers tailored just for you!