---
title: Environment variables
slug: hosty/environment-variables
createdAt: 2026-11-08T11:27:49.007Z
---

Your application gets its settings from environment variables: the ones you set in `hosty.yaml`, and the ones Hosty adds, such as the credentials of the database. This page lists what Hosty adds and how you can use tokens in `hosty.yaml`.

## Your variables

Set variables for each container in `environmentVariables`, or load them from files with `environmentFiles` (see [Sensitive environment variables](https://wiki.systemseed.com/hosty/sensitive-environment-variables)):

```yaml
applications:
  backend:
    php:
      environmentVariables:
        APP_MODE: development
        PHP_FPM_PM_MAX_CHILDREN: "30"
      environmentFiles:
        - ./.env.secrets
```

- Names are uppercase letters, digits and `_`. Values are strings: quote numbers and booleans.
- A variable in a file wins over the same variable in `environmentVariables`.
- The variables are built into the image, so the build hook has them too. Changing a value builds a new image on the next deployment.
- Variables of the `php`, `python` and `node` sections go to the application, those of `nginx` and `apache` to the web server. The Wodby images read many variables of their own, listed in their README files: [PHP](https://github.com/wodby/php#environment-variables), [nginx](https://github.com/wodby/nginx#environment-variables), [Apache](https://github.com/wodby/apache#environment-variables), [Python](https://github.com/wodby/python#environment-variables) and [Node.js](https://github.com/wodby/node#environment-variables).

## Variables Hosty adds

### Every application

| Variable               | Value                                                                                                                                                                       | Can be overridden |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `HOSTY_PROJECT`        | Name of the project.                                                                                                                                                        | No                |
| `HOSTY_ENVIRONMENT`    | Name of the environment, i.e. `production` or `feature-123`.                                                                                                                | No                |
| `FILES_<STORAGE>_PATH` | Absolute path of each [persistent storage](https://wiki.systemseed.com/hosty/project-configuration#persistent-storages), i.e. `FILES_PUBLIC_PATH` for the storage `public`. | No                |
| `COLUMNS`              | `120`, the width of the terminal for command-line tools.                                                                                                                    | Yes               |

### Database

PHP and Python applications get the database of the environment. Node.js applications have none.

| Variable         | Value                                                                               |
| ---------------- | ----------------------------------------------------------------------------------- |
| `DB_DRIVER`      | `mysql` or `pgsql`, by the database of the cluster.                                 |
| `DB_HOST`        | Host of the database for reads and writes.                                          |
| `DB_HOST_READER` | Host of the read-only replicas. Use it only for reads that may lag a little behind. |
| `DB_PORT`        | Port of the database.                                                               |
| `DB_NAME`        | Name of the database of the environment.                                            |
| `DB_USER`        | User of the database.                                                               |
| `DB_PASSWORD`    | Password of the user.                                                               |

On MySQL, `DB_USER` is `<project>_production` on production and `<project>_development` on development environments. An application with `database.from` gets the values of the application whose database it uses.

### Redis

With `services.redis` in `hosty.yaml`, all applications get:

| Variable         | Value                             |
| ---------------- | --------------------------------- |
| `REDIS_HOST`     | Host of Redis of the environment. |
| `REDIS_PORT`     | `6379`.                           |
| `REDIS_PASSWORD` | Password of Redis.                |

### Search

With `search` in `hosty.yaml`, PHP and Python applications get:

| Variable                    | Value                                                                                                     |
| --------------------------- | --------------------------------------------------------------------------------------------------------- |
| `OPENSEARCH_URL`            | Address of the OpenSearch domain, i.e. `https://<endpoint>:443`.                                          |
| `OPENSEARCH_USERNAME`       | User of the environment.                                                                                  |
| `OPENSEARCH_PASSWORD`       | Password of the user.                                                                                     |
| `OPENSEARCH_INDEX_PREFIX`   | Prefix your indices must start with. The user can't reach other indices.                                  |
| `OPENSEARCH_INDEX_REPLICAS` | Number of replicas to create indices with: `1` on production with more than one data node, `0` otherwise. |

### PHP

PHP-FPM passes only a list of variables to PHP (`PHP_FPM_CLEAR_ENV` is `yes`): your variables, the ones above, and the database, Redis and search variables. Hosty builds the list in `PHP_FPM_ENV_VARS`, so you don't set either of them.

On production, PHP runs 20 php-fpm workers per pod (`PHP_FPM_PM_MAX_CHILDREN`). Set the variable in `php` to change it.

### nginx

| Variable                    | Default                                                                                                                     | Can be overridden |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `NGINX_REAL_IP_HEADER`      | `X-Forwarded-For`                                                                                                           | Yes               |
| `NGINX_REAL_IP_RECURSIVE`   | `on`                                                                                                                        | Yes               |
| `NGINX_SET_REAL_IPS_FROM`   | The private networks, where the load balancers are, and the IPv4 ranges of Cloudflare.                                      | Yes               |
| `NGINX_LOG_FORMAT_OVERRIDE` | `$http_x_forwarded_for - $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"` | Yes               |
| `NGINX_MODSECURITY_ENABLED` | `1`, the [ModSecurity](https://github.com/wodby/nginx#modsecurity) firewall is on.                                          | Yes               |
| `NGINX_BACKEND_HOST`        | `127.0.0.1`                                                                                                                 | No                |
| `NGINX_BACKEND_PORT`        | `9000` for PHP, the `port` of Python                                                                                        | No                |
| `NGINX_HTTP2`               | `on`                                                                                                                        | No                |

With the first three, the backend gets the address of the visitor instead of the one of the load balancer, i.e. in `REMOTE_ADDR` of PHP. Visitors can't fake it, as nginx trusts only the load balancers and Cloudflare. Node.js applications have no nginx: read the address from `X-Forwarded-For` yourself.

### Apache

| Variable               | Default       | Can be overridden |
| ---------------------- | ------------- | ----------------- |
| `APACHE_TIMEOUT`       | `120` seconds | Yes               |
| `APACHE_SERVER_TOKENS` | `Prod`        | Yes               |
| `APACHE_VHOST_PRESET`  | `php`         | No                |
| `APACHE_BACKEND_HOST`  | `127.0.0.1`   | No                |
| `APACHE_HTTP2`         | `on`          | No                |

## Tokens

Values in `hosty.yaml`, variables included, can use tokens, which the `build` and `deploy` commands replace:

| Token                          | Value                                                                                                                             |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `{{ projectName }}`            | Name of the project.                                                                                                              |
| `{{ clusterName }}`            | Name of the cluster.                                                                                                              |
| `{{ hostedZone }}`             | The domain of the hosting, which the default domains of environments end with.                                                    |
| `{{ environmentName }}`        | Name of the environment.                                                                                                          |
| `{{ <application>.name }}`     | Name of the application, i.e. `{{ backend.name }}`.                                                                               |
| `{{ <application>.host.<N> }}` | Domain number N of the application, counting from 0. `{{ backend.host.0 }}` is the first domain of `backend` on this environment. |

For example, a frontend that calls the API of the backend:

```yaml
applications:
  frontend:
    node:
      environmentVariables:
        API_URL: "https://{{ backend.host.0 }}/api"
```

- Write a token exactly as in the table, with one space inside the braces.
- Tokens are replaced after the [overrides](https://wiki.systemseed.com/hosty/project-configuration#overrides), so a host token gives the domain from `hosts` on production.
- Applications with `ingress: false` have no domains, so their host tokens stop the build with an error.
- Tokens don't work in environment files.
