Gustavo Hoirisch
Gustavo Hoirisch

Reputation: 1657

'Setup Python App' feature on cPanel shared hosting

I have just found out this "feature" under my web hosting cPanel called "Setup Python App" and very much would like to play around with a nice flask app if I could however it does not seem to work so I come here looking for some help. Here is a brief description of the setup and it's symptoms:

cpanel setup python application

Clicking on this takes me to a very simple page asking for a directory and URI however when "setting it up" not much information is reported back but a directory is generated with a passenger_wsgi.py file with what looks like a basic server setup however trying to land on it simply downloads the file.

setting up options post setup

passenger_wsgi.py

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!\n'
    version = 'Python %s\n' % sys.version.split()[0]
    response = '\n'.join([message, version])
    return [response.encode()]

To solve this I figured I would setup an Apache Handler to include .py under the cgi-script handlers which then makes landing on this page a simple 500 Server Error.

500 Internal Error

I am running out of ideas on how to get this working and can't find any documentation about this "Setup Python App" feature. If anyone has had experience with it I would very much appreciate some assistance. I have already reached out to web hosting support and they also do not know what is going on. I do suspect that there is a phusion passenger server that gets setup in the process but not correctly maybe? Also there doesn't seem to be a way for me to know which port it is running under and no redirect is automatically generated (I say this because when generating a Rails app an internal redirect is automatically created pointing to the correct internal port, which I would expect to happen here too).

Upvotes: 1

Views: 8400

Answers (1)

taiff
taiff

Reputation: 89

I've had the Python file set at 644 and added the following to the top of my .htaccess file to allow both root URL and non-root URL to work:

RewriteEngine on
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

Got this info from: https://stackoverflow.com/a/63971427/10122266

Apologies that I couldn't add this as a comment as I do not have sufficient rights yet. But this solution worked for me and it would be a pitty if this little gem is hidden from those who may arrive here.

So would appreciate if this post is not deleted.

Upvotes: 1

Related Questions