How to restart my app and set environment variables

When should I restart my application?

Restart your Node.js or Python application after every:

  • Code change
  • Dependency installation or upgrade
  • Startup-file change
  • Environment-variable change
  • Configuration change

Passenger may continue using the previous version until the application is restarted.

Restart the application from the control panel

  1. Sign in to cPanel or a compatible DirectAdmin server.
  2. Open your Node.js or Python application (cPanel: Software → Setup Node.js App or Setup Python App).
  3. Select Restart.
  4. Open the application's URL to start a new request.
  5. Check that your changes are active.

Passenger starts applications when requests arrive. A restart does not make the application run continuously in the background.

Restart the application over SSH

Passenger also restarts the application when a restart marker inside the application root is created or updated:

mkdir -p tmp
touch tmp/restart.txt

Run these commands from your application root.

The control-panel Restart button is the preferred method.

Add an environment variable

  1. Open the application in the app manager.
  2. Find the environment variables area.
  3. Select Add Variable.
  4. Enter the variable's name.
  5. Enter its value.
  6. Save the application.
  7. Restart it.

Environment-variable names are case-sensitive. For example, DATABASE_URL and database_url are different names.

Common variables include:

Variable Typical purpose
NODE_ENV Selects the Node.js environment
FLASK_ENV Flask environment configuration
DJANGO_SETTINGS_MODULE Selects the Django settings module
DATABASE_URL Database connection information
SECRET_KEY Application signing or encryption secret
API_KEY Credentials for an external service

Use the names expected by your own application or framework.

Read variables in Python

Python applications can read injected variables through os.environ:

import os

database_url = os.environ.get("DATABASE_URL")

Avoid placing secret values directly in the source code.

Read variables in Node.js

Node.js applications can read injected variables through process.env:

const databaseUrl = process.env.DATABASE_URL;

Restart the application after adding or changing the value.

Using a .env file

The app manager does not automatically load your application's .env file.

Your application must load it itself, for example with:

  • python-dotenv for Python
  • dotenv for Node.js

Keep .env outside public_html and do not commit it to a public Git repository.

A variable added through the control panel is injected directly into the application environment and does not require a .env file.

Background tasks and WebSockets

These shared-hosting applications start in response to web requests and may stop when idle.

They are not suitable for:

  • Always-running worker processes
  • Permanent queue consumers
  • WebSocket servers
  • Services that must remain active without web traffic

Use scheduled tasks (cron jobs) for short periodic jobs where appropriate.

Did this answer it?