import sys import os # Ensure cPanel knows where your application files live sys.path.insert(0, os.path.dirname(__file__)) # 1. Initialize the a2wsgi bridge safely from a2wsgi import ASGIMiddleware # 2. Delayed wrapper function to prevent early thread crashes class PassengerApplication: def __init__(self): self._app = None def __call__(self, environ, start_response): if self._app is None: # Import main only when the first web request hits the server from main import fastapi_app self._app = ASGIMiddleware(fastapi_app) return self._app(environ, start_response) # Passenger looks exactly for this variable application = PassengerApplication()