Configure environment variables
Back to home
On this page
By default, Upsun exposes some environment variables. If you’re using the Symfony integration, more infrastructure environment variables related to Symfony are defined.
As Symfony relies heavily on environment variables to configure application services (such as the database or the mailer DSN), the Symfony integration automatically defines environment variables for all the services connected to your app.
Tip
The code that defines these additional environment variables is part of the open-source Symfony CLI tool. Check the code for infrastructure and service environment variables on GitHub.
Symfony environment variables
Upsun exposes environment variables about the app and its infrastructure.
The Symfony integration exposes more environment variables:
-
APP_ENV
is set toprod
by default. You can manually override this value for a preview environment by setting theSYMFONY_ENV
environment variable todev
, and remove it when done. -
APP_DEBUG
is set to0
by default. You can manually override this value for a preview environment by setting theSYMFONY_DEBUG
environment variable to1
, and remove it when done. -
APP_SECRET
is set to the value ofPLATFORM_PROJECT_ENTROPY
, which is a random and unique value for all Upsun projects. It overrides the value configured in the.env
file of your app. -
MAILFROM
is set to a random value. This value is used as aFrom
header when using croncape. -
SYMFONY_IS_WORKER
is set to1
when the container is running in the context of a worker (instead of the main application container). -
SYMFONY_CACHE_DIR
(only available during the build hook execution): The absolute path to a subdirectory of your build cache directory.Note that the build cache directory is persisted between builds but isn’t deployed. Itโs a good place to store build artifacts, such as downloaded files that can be reused between builds.
Tip
This directory is shared by all builds on all branches. Make sure your build hook accounts for that.
If you need to clear the build cache directory, run the
symfony upsun:project:clear-build-cache
command. -
SYMFONY_PROJECT_DEFAULT_ROUTE_URL
(only defined at runtime): The default endpoint serving your project. Use this variable to avoid hard-coding domains that can be used to reach preview environments. Parts of the URL are also exposed as their own variables using the following syntax:SYMFONY_PROJECT_DEFAULT_ROUTE_
followed by the name of the part (SCHEME
,DOMAIN
,PORT
, andPATH
).Guessing the default endpoint can prove difficult for multi-routes or multi-app projects. In such cases, the following preference order is used:
- Project-wide route defined only by
{default}
or{all}
(no path) - Project-wide route defined by
www.{default}
orwww.{all}
(no path) - Route for the current application including
{default}
or{all}
(might include a path) - Route for the current application including
www.{default}
orwww.{all}
(might include a path) - First route for the current application
- First route for the whole project
When several routes match a rule, the first one wins, the user order is kept. There’s no preference regarding protocols.
Tip
If you have a multi-app project containing several publicly reachable apps, you might need to determine the current application endpoint (for webhooks for example) and the project endpoint (to send emails for example).
In this case, you can use an additional
SYMFONY_APPLICATION_DEFAULT_ROUTE_*
set of environment variables. The same rules are applied to determine their value, but only routes matching the current application are evaluated. - Project-wide route defined only by
Service environment variables
When using the Symfony integration, information about services are exposed via environment variables.
To list all of the exposed environment variables, run the following command:
symfony ssh -- symfony var:export --multiline
Each exposed environment variable is prefixed by the relationship name. For example, if you have the following relationships in your configuration:
applications:
myapp:
relationships:
database:
service: securitydb
endpoint: 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.
Most environment variable names are derived from the relationship and service names.
But some are defined based on Symfony conventions, such as MAILER_DSN
.
Note
Environment variables aren’t exposed when the build hook script is running as services aren’t available during the build process.
Emails
The configuration is exposed via the following environment variables:
MAILER_ENABLED
: 1 if outgoing emails are enabled, 0 otherwiseMAILER_DSN
/MAILER_URL
: The Symfony-compatible mailer URLMAILER_HOST
: The SMTP server hostMAILER_PORT
: The SMTP server portMAILER_TRANSPORT
: The SMTP transport mode (smtp
)MAILER_AUTH_MODE
: The SMTP auth mode (plain
)MAILER_USER
: The SMTP server userMAILER_PASSWORD
: The SMTP server password
Symfony Mailer automatically uses the value of MAILER_DSN
.
HTTP
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 serviceSOME_SERVICE_IP
: The HTTP service IPSOME_SERVICE_PORT
: The HTTP service portSOME_SERVICE_SCHEME
: The HTTP service schemeSOME_SERVICE_HOST
: The HTTP service host
MySQL/MariaDB
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 serverDATABASE_DRIVER
: The database driverDATABASE_VERSION
: The database versionDATABASE_HOST
: The database hostDATABASE_PORT
: The database portDATABASE_NAME
: The database nameDATABASE_DATABASE
: Alias forDATABASE_NAME
DATABASE_USERNAME
: The database usernameDATABASE_PASSWORD
: The database password
Tip
The database version and a default charset are included in the database URL.
To override them, use the DATABASE_VERSION
and DATABASE_CHARSET
environment variables respectively.
PostgreSQL
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 serverDATABASE_DRIVER
: The database driverDATABASE_VERSION
: The database versionDATABASE_HOST
: The database hostDATABASE_PORT
: The database portDATABASE_NAME
: The database nameDATABASE_DATABASE
: Alias forDATABASE_NAME
DATABASE_USERNAME
: The database usernameDATABASE_PASSWORD
: The database password
Tip
The database version and a default charset are included in the database URL.
To override them, use the DATABASE_VERSION
and DATABASE_CHARSET
environment variables respectively.
Redis
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 URLREDIS_HOST
: The Redis hostREDIS_PORT
: The Redis portREDIS_SCHEME
: The Redis scheme
Memcached
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
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 serviceELASTICSEARCH_HOST
: The Elasticsearch hostELASTICSEARCH_PORT
: The Elasticsearch portELASTICSEARCH_SCHEME
: The Elasticsearch protocol scheme (http
orhttps
)
Solr
The Apache Solr configuration is exposed via the following environment variables
(where SOLR
is the upper-cased version of the key defined in the relationship):
SOLR_HOST
: The Solr hostSOLR_PORT
: The Solr portSOLR_NAME
: The Solr nameSOLR_DATABASE
: An alias forSOLR_NAME
RabbitMQ
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 URLRABBITMQ_SERVER
: The RabbitMQ serverRABBITMQ_HOST
: The RabbitMQ hostRABBITMQ_PORT
: The RabbitMQ portRABBITMQ_SCHEME
: The RabbitMQ schemeRABBITMQ_USER
: The RabbitMQ usernameRABBITMQ_USERNAME
: The RabbitMQ usernameRABBITMQ_PASSWORD
: The RabbitMQ password
MongoDB
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
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
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