How to use a Python application on cPanel hosting

Procédure

The Python ecosystem with our cPanel packages

Python is a very popular computer programming language and is now one of the languages used to create and deploy websites and online applications.

The cPanel web hosting packages from LWS support the use of Python in the shared web hosting environment. You can select the Python version of your choice and integrate it into the existing web service using Phusion Passenger and WSGI interfaces.

What is Phusion Passenger?

To provide our customers with a stable, robust and secure environment, we integrate your Python applications with the Apache web service using the Phusion Passenger tool.

We do not set up a reverse proxy, and Python applications cannot run standalone on their own web server. Your Python application will not listen on any port, it will communicate exclusively in WSGI with the Passenger service. If you use a framework, find out whether it is compatible with Phusion Passenger and WSGI interfaces.

How do I install an application written in Python?

From your cPanel control panel, find the Setup Python App icon in the Software section.

How to use a Python application on cPanel hosting

On the page that follows, click on the ' Create Application ' button to add a new application.

How to use a Python application on cPanel hosting

Then fill in the fields according to your application's requirements:

  • Python version: This option lets you select a specific Python version for your application.
  • Application root : the location of your Python application, relative to your FTP root. We recommend that you do not put your Python application in the public_html folder.
  • Application URL: the root URL of your Python application.
  • Application startup file : the .py file containing the initialisation of your WSGI object (relative path to application root).
  • Application Entry point : the name of your WSGI object in the file defined in Application startup file.

How to use a Python application on cPanel hosting

Then click on the " Create " button once your application has been set up.

If your application startup file does not yet exist, the tool will immediately create this file with sample content. This example will display " It works! " on all HTTP requests associated with it.

Here are the contents of this example script :

import os import sys sys.path.insert(0, os.path.dirname(__file__)) def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) message = 'It works!\version = 'Python %s\n' % sys.version.split()[0] response = '\n'.join([message, version]) return [response.encode()]

Accessing your application from the terminal

Using the terminal on the command line is an integral part of the Python ecosystem. To access your application's environment from the terminal, connect to it (from the cPanel web terminal or from an SSH client) and copy the command shown to enter your application's environment:

How to use a Python application on cPanel hosting

This action will automatically activate the correct virtual environment for your application, including the correct version of Python and PIP, as well as any dependencies installed in the environment.

Exclude a folder/subdomain from the Python processor

Note that if your Python application is in your public_html folder, then all subfolders will be covered by the application. This behaviour can be modified, especially if you have, for example, a subfolder in your public_html attached to another domain name or subdomain.

To do this, add the following to the .htaccess file for the folder you don't want your Python application to run in:

PassengerEnabled off

This will then disable Phusion Passenger which is the connector between your Python application and your web server. Note that this will also affect all subfolders.

Debugging a Python application

To debug a Python application, you can consult the Apache error log. The Apache error log file contains :

  • STDOUT and STDERR output from the Python application
  • Passenger errors
  • Apache errors

If you have manually set the PassengerLogFile value in your site's .htaccess file, the STDOUT and STDERR output and Passenger-related errors are sent to this file instead of the Apache log file.

You can also set the PassengerFriendlyErrorPages value to on in your .htaccess file to display errors relating to the start-up of your Python application directly on the web browser.

Rate this article :

4/5 | 2 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How to use a Node.js application on cPanel hosting

1mn reading

How to use a Ruby application on cPanel hosting


Questions sur l'article
Christopher pande Il y a 766 days
Comment utiliser lws cpanel avec différents adresse IP pour la connexion. Parce qu'on bloque d'autres adresses !. Si je me connecte avec un autre modem , car je ne suis plus le seul a utiliser l'interface cpanel svp
See the
1 answers
fabrice-LWS - Il y a 752 days
Bonjour, il est tout à fait possible de vous connecter à LWS Panel, de différents endroits sans problème. Lors de la connexion, si l'adresse IP n'est pas connu par le système, vous devriez recevoir un email avec un code de connexion. Si l'ip est déjà connu par le système pour s'être déjà connecté à votre espace client, plus aucun code ne sera envoyé par email et la connexion s'effectuera de suite à l'espace client.
Utile ?
julien-LWS Il y a 648 days
Bonjour, J'ai une application Python conçue avec le framework Streamlit. Alors je voulais savoir s'il existe un moyen de l'héberger sur LWS Panel. Bien merci et coordialement
See the
1 answers
fabrice-LWS - Il y a 638 days
Bonjour, afin d'héberger une application Python, je vous invite à souscrire à une formule cPanel. Vous pouvez prendre connaissance des formules cPanel en vous rendant sur la page suivante: https://www.lws.fr/hebergement-cpanel.php
Utile ?
AlidWatt Il y a 605 days
Bonjour l' equipe lws. Es qu il ya la possibilite d' heberger des applications flask sur votre ici?
See the
1 answers
Benjamin-LWS - Il y a 604 days

Bonjour, merci pour votre question.

Flask étant un framework utilisant python, son implémentation au sein d'un hébergement cPanel est possible.

Nous vous invitons à contacter notre service support à travers votre espace client, afin de vous apporter une aide si vous en avez besoin. (https://aide.lws.fr/a/268)

Utile ?
Rcsjlim Il y a 589 days
Bonjour, Est-ce possible d'utiliser le package FPDF (création de fichiers PDF) pour Python dans cPanel ?
See the
1 answers
Benjamin-LWS - Il y a 585 days

Bonjour,

Merci de votre retour,

Oui, c'est possible d'utiliser le package FPDF (création de fichiers PDF) pour Python dans cPanel. 

L'installation de ce package peut se faire avec la commande "pip install fpdf".

Je vous remercie pour votre attention et reste à votre disposition pour toute autre question ou complément d'information.

Vous pouvez également contacter notre support technique pour obtenir de l'aide. (https://aide.lws.fr/a/268)

Utile ?
Pilipili kasay Il y a 584 days
Vraiment je ne comprends rien concernant l'hébergement des applications conçues en Django. Juste j'ai besoin des procédures pour mettre mon projet Django sur le gestionnaire de fichiers cpanel. Je possède un compte et un espace d'hébergement sur Lws
See the
1 answers
Benjamin-LWS - Il y a 584 days

Bonjour,

Merci de votre retour.

Si vous avez acheté votre domaine il y a plus de trois jours malheureusement, vous ne pouvez pas modifier le nom d'un domaine déjà payé contre un autre disponible.

Dans le cas où vous avez acheté votre domaine il y a moins de trois jours, vous avez la possibilité de recommander le domaine que vous souhaitez et de vous faire rembourser celui que vous ne souhaitez plus avoir. Il faudra ouvrir un contact sur notre plateforme de support disponible pour nos clients dans leur espace LWS.

Je vous remercie pour votre attention et reste à votre disposition pour toute autre question ou complément d'information.

Nous vous invitons à contacter notre service support à travers votre espace client, afin de vous apporter une aide si vous rencontrez des difficultés quelconque. (https://aide.lws.fr/a/268)

Cordialement, L'équipe LWS

Utile ?
LWS-513659 Il y a 554 days
Pourquoi le gestionnaire d'application Python, n'est pas disponible sur mon CPanel ?
See the
1 answers
Benjamin-LWS - Il y a 552 days

Bonjour,

Merci pour votre retour.

Sur toutes nos formules cPanel le gestionnaire d'applications Python (Setup App Python) est disponible.

Si vous ne trouvez pas cette onglet sur le cPanel, je vous invite à aller sur la barre de recherche de votre cPanel, et à écrire "Python", il vous proposera en premier lieu l'onglet "Setup App Python".

Si malgré cette solution vous ne parvenez pas à trouver votre gestionnaire d'application Python, revenez vers nous directement via le support technique disponible depuis votre espace client. (https://aide.lws.fr/a/264)

Je vous remercie de votre attention.

Cordialement, L'équipe LWS 

Utile ?
Sorosoro Il y a 402 days
Et pour le changement de la base de données Sqlite par défaut en postgreSQL?
See the
1 answers
Aurelien-LWS - Il y a 397 days

Bonjour, 

Je vous remercie pour votre message.

Pour utiliser PostgreSQL avec une application Python, vous devez installer "psycopg2", le pilote Python pour PostgreSQL en effectuant la commande :
pip install psycopg2

Vous devez ensuite créer une base de données PostgreSQL et modifier la chaine de connexion à la base de données dans votre application Python pour qu'elle se connecte à cette base.

Si vous utilisez un ORM, vous devrez probablement effectuer une migration pour créer les tables dans la nouvelle base de données. Par exemple, avec Django, vous utiliserez :
python manage.py migrate

Si vous avez des données existantes dans SQLite que vous souhaitez transférer vers PostgreSQL, vous devrez utiliser un outil ou écrire un script pour effectuer cette opération. Il existe des outils comme "pgloader" qui peuvent faciliter ce processus.

Cordialement, L'équipe LWS

Utile ?

Ask the LWS team and its community a question