INFO: DirectAdmin - Creating a Python Application

Applies To:

  • Linux Web Hosting - with Python Support

Important:

  • This is a 'beta' article which may be subject to errors and revisions.
  • Python is supported within the constraints of the Cloudlinux implementation managed via DirectAdmin.
  • Python applications are an advanced topic for experienced developers only.
  • Python is supported but not application development and debugging.
  • Python in a shared environment is designed for small scale, light usage.

Article:

Field-by-field guidance for the CloudLinux Python Selector Create Application page in DirectAdmin. To access:

 

  1. Logon to DirectAdmin (https://www.example.com:2222/)
  2. Click Extra Features then Setup Python App
  3. Click Create Application to reveal the setup page:

 

Example assumptions
  • DirectAdmin username: exampleuser
  • Domain: example.com
  • Application directory: /home/exampleuser/apps/myapp
  • Application URL: https://example.com/myapp

Recommended field values

Field Value to enter
Python version Select the version required by the application, commonly Python 3.11 or 3.12 where available.
Application root apps/myapp
Application URL Select example.com, then enter /myapp as the URI.
Application startup file passenger_wsgi.py
Application entry point application
Passenger log file /home/exampleuser/logs/myapp-passenger.log

Field explanations

Python version

Select the Python version supported by the application and its dependencies. For a new application, Python 3.11 or 3.12 is usually appropriate where CloudLinux provides it.

Do not automatically select the highest available version. Check the application's documentation, development environment, and requirements.txt for compatibility.

Application root

Enter the application's directory relative to the DirectAdmin user's home directory:

apps/myapp

This corresponds to the full filesystem path:

/home/exampleuser/apps/myapp

Do not normally enter the full path in the Application root field. Also avoid placing the application source directly inside public_html unless the application specifically requires it.

A suitable directory layout is:

/home/exampleuser/apps/myapp/
├── passenger_wsgi.py
├── requirements.txt
├── app.py
└── other application files
Avoid naming the application directory after a Python runtime, such as python311 or python312. A descriptive application name is clearer and avoids potential conflicts.

Application URL

Select the relevant domain and specify the URI at which the application will be published.

To publish at the domain root:

Domain: example.com
URI:    /

The application will be available at:

https://example.com/

To publish below a path:

Domain: example.com
URI:    /myapp

The application will be available at:

https://example.com/myapp

For a dedicated subdomain, create the subdomain in DirectAdmin first, then select it and use / as the URI:

Domain: app.example.com
URI:    /

A dedicated subdomain is generally cleaner for framework applications, particularly where the application generates URLs or serves static files.

Application startup file

Enter:

passenger_wsgi.py

The file must exist directly in the application root:

/home/exampleuser/apps/myapp/passenger_wsgi.py

Passenger loads this file when starting the Python application.

Application entry point

Enter:

application

This is the name of the WSGI callable exposed by passenger_wsgi.py. For example:

from app import app as application

The field expects the callable name. It does not expect a filename, filesystem path, module path, or function invocation.

Do not enter values such as:

app.py
passenger_wsgi.py
application()

Passenger log file

Enter an absolute path that is writable by the DirectAdmin user:

/home/exampleuser/logs/myapp-passenger.log

Create the log directory first if necessary:

mkdir -p ~/logs

An alternative is to keep the log inside the application directory:

/home/exampleuser/apps/myapp/passenger.log

Using a dedicated ~/logs directory is usually easier to manage.

Environment variables

Add only the variables required by the application. Common examples include:

Variable Example value
APP_ENV production
FLASK_ENV production
DJANGO_SETTINGS_MODULE myproject.settings
SECRET_KEY A long, randomly generated value
DATABASE_URL The application's database connection string
DEBUG False
Do not store passwords, API keys, or other secrets in files beneath public_html. Use application environment variables or another protected configuration mechanism.

Flask example

Create Application values

Python version:           3.11
Application root:         apps/myapp
Application URL:          example.com /myapp
Application startup file: passenger_wsgi.py
Application entry point:  application
Passenger log file:       /home/exampleuser/logs/myapp-passenger.log

app.py

from flask import Flask

app = Flask(__name__)

@app.get("/")
def index():
    return "Flask application is working"

passenger_wsgi.py

from app import app as application

requirements.txt

Flask

Django example

Create Application values

Python version:           3.11
Application root:         apps/mydjango
Application URL:          example.com /
Application startup file: passenger_wsgi.py
Application entry point:  application
Passenger log file:       /home/exampleuser/logs/mydjango-passenger.log

passenger_wsgi.py

Assuming the Django project package is named myproject:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

The environment variable may also be entered in the Python Selector:

DJANGO_SETTINGS_MODULE = myproject.settings

After creating the application

  1. Upload or create the application files under the configured application root.
  2. Use the Python Selector's Run pip install facility against requirements.txt, where available.
  3. Return to the Python Selector and click Restart Application.
  4. Review the configured Passenger log if the application returns an error.
Restart the application after changing Python source files, dependencies, the startup file, or environment variables so that Passenger reloads the application.


Was this article helpful?

mood_bad Dislike 0
mood Like 12
visibility Views: 1049