Upsun User Documentation

Configure environment variables

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!ยน A monthly $19 perk!
ยนTerms and conditions apply
Activate your 15-day trial

By default, Upsun exposes some environment variables.

Laravel relies heavily on environment variables to configure application services (such as the database or the mailer). Therefore, the default configuration generated by upsun project:init includes the environment variables for all the services connected to your app in the .environment file.

Default environment variables Anchor to this heading

Upsun automatically exposes environment variables about the app and its infrastructure.

Assuming that MySQL, PostgreSQL, and Redis services have been added to your environment, and that the app has been granted access to those services via the following relationships:

.upsun/config.yaml
applications:
    myapp:
        ...
        relationships:
            mysql: ...
            postgresql: ...
            redis: ...

You can transpose these variables to set up Laravel’s default configuration in a .environment file:

.environment
# Set MySQL database environment variables
export DB_HOST="$MYSQL_HOST"
export DB_PORT="$MYSQL_PORT"
export DB_PATH="$MYSQL_PATH"
export DB_USERNAME="$MYSQL_USERNAME"
export DB_PASSWORD="$MYSQL_PASSWORD"
export DB_SCHEME="$MYSQL_SCHEME"
export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_PATH}"

# Or for PostgreSQL
export DB_HOST="$POSTGRESQL_HOST"
export DB_PORT="$POSTGRESQL_PORT"
export DB_PATH="$POSTGRESQL_PATH"
export DB_USERNAME="$POSTGRESQL_USERNAME"
export DB_PASSWORD="$POSTGRESQL_PASSWORD"
export DB_SCHEME="$POSTGRESQL_SCHEME"
export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_PATH}"

# Set Laravel-specific environment variables
export DB_CONNECTION="$DB_SCHEME"
export DB_DATABASE="$DB_PATH"

# Set Cache environment variables
export CACHE_HOST="$REDIS_HOST"
export CACHE_PORT="$REDIS_PORT"
export CACHE_SCHEME="$REDIS_SCHEME"
export CACHE_URL="${CACHE_SCHEME}://${CACHE_HOST}:${CACHE_PORT}"

# Set Redis environment variables
export REDIS_URL="$CACHE_URL"

Service environment variables Anchor to this heading

Each exposed environment variable is prefixed by the relationship name. For example, if you have the following relationships in your configuration:

.upsun/config.yaml
relationships:
    database: "securitydb:postgresql"

The environment variables for the database service is prefixed by DATABASE_, which is the upper-cased version of the key defined in the relationship. For example, you could have a DATABASE_URL environment variable.

Emails Anchor to this heading

Upsun provides a SMTP service for sending emails. To configure email in Laravel, add the following mapping to your .environment file:

.environment
# Email
export MAIL_MAILER="smtp"
export MAIL_HOST="${PLATFORM_SMTP_HOST}"
export MAIL_PORT="25"

HTTP Anchor to this heading

If your project has multiple apps, the configuration is exposed via the following environment variables (where SOME_SERVICE is the upper-cased version of the key defined in the relationship):

  • SOME_SERVICE_URL: The full URL of the service
  • SOME_SERVICE_IP: The HTTP service IP
  • SOME_SERVICE_PORT: The HTTP service port
  • SOME_SERVICE_SCHEME: The HTTP service scheme
  • SOME_SERVICE_HOST: The HTTP service host

MySQL/MariaDB Anchor to this heading

The MySQL/MariaDB configuration is exposed via the following environment variables (where DATABASE is the upper-cased version of the key defined in the relationship above):

  • DATABASE_URL: The database URL (in PHP or Go format depending on your app)
  • DATABASE_SERVER: The database server
  • DATABASE_DRIVER: The database driver
  • DATABASE_VERSION: The database version
  • DATABASE_HOST: The database host
  • DATABASE_PORT: The database port
  • DATABASE_NAME: The database name
  • DATABASE_DATABASE: Alias for DATABASE_NAME
  • DATABASE_USERNAME: The database username
  • DATABASE_PASSWORD: The database password

PostgreSQL Anchor to this heading

The PostgreSQL configuration is exposed via the following environment variables (where DATABASE is the upper-cased version of the key defined in the relationship):

  • DATABASE_URL: The database URL (in PHP or Go format depending on your app)
  • DATABASE_SERVER: The database server
  • DATABASE_DRIVER: The database driver
  • DATABASE_VERSION: The database version
  • DATABASE_HOST: The database host
  • DATABASE_PORT: The database port
  • DATABASE_NAME: The database name
  • DATABASE_DATABASE: Alias for DATABASE_NAME
  • DATABASE_USERNAME: The database username
  • DATABASE_PASSWORD: The database password

Redis Anchor to this heading

The Redis configuration is exposed via the following environment variables (where REDIS is the upper-cased version of the key defined in the relationship):

  • REDIS_URL: The Redis URL
  • REDIS_HOST: The Redis host
  • REDIS_PORT: The Redis port
  • REDIS_SCHEME: The Redis scheme

You can specify the Redis client in your .environment file:

.environment
export REDIS_CLIENT="phpredis"

Memcached Anchor to this heading

The Memcached configuration is exposed via the following environment variables (where CACHE is the upper-cased version of the key defined in the relationship):

  • CACHE_HOST
  • CACHE_PORT
  • CACHE_IP

Elasticsearch Anchor to this heading

The Elasticsearch configuration is exposed via the following environment variables (where ELASTICSEARCH is the upper-cased version of the key defined in the relationship):

  • ELASTICSEARCH_URL: The full URL of the Elasticsearch service
  • ELASTICSEARCH_HOST: The Elasticsearch host
  • ELASTICSEARCH_PORT: The Elasticsearch port
  • ELASTICSEARCH_SCHEME: The Elasticsearch protocol scheme (http or https)

RabbitMQ Anchor to this heading

The RabbitMQ configuration is exposed via the following environment variables (where RABBITMQ is the upper-cased version of the key defined in the relationship):

  • RABBITMQ_URL: The RabbitMQ standardized URL
  • RABBITMQ_SERVER: The RabbitMQ server
  • RABBITMQ_HOST: The RabbitMQ host
  • RABBITMQ_PORT: The RabbitMQ port
  • RABBITMQ_SCHEME: The RabbitMQ scheme
  • RABBITMQ_USER: The RabbitMQ username
  • RABBITMQ_USERNAME: The RabbitMQ username
  • RABBITMQ_PASSWORD: The RabbitMQ password

MongoDB Anchor to this heading

The MongoDB configuration is exposed via the following environment variables (where MONGODB is the upper-cased version of the key defined in the relationship):

  • MONGODB_SERVER
  • MONGODB_HOST
  • MONGODB_PORT
  • MONGODB_SCHEME
  • MONGODB_NAME
  • MONGODB_DATABASE
  • MONGODB_USER
  • MONGODB_USERNAME
  • MONGODB_PASSWORD

InfluxDB Anchor to this heading

The InfluxDB configuration is exposed via the following environment variables (where TIMEDB is the upper-cased version of the key defined in the relationship):

  • TIMEDB_SCHEME
  • TIMEDB_HOST
  • TIMEDB_PORT
  • TIMEDB_IP

Kafka Anchor to this heading

The Apache Kafka configuration is exposed via the following environment variables (where KAFKA is the upper-cased version of the key defined in the relationship):

  • KAFKA_URL
  • KAFKA_SCHEME
  • KAFKA_HOST
  • KAFKA_PORT
  • KAFKA_IP

Is this page helpful?