Bring your own env.php
This document explains how to provide your own env.php
file when using Mappia. By default, Mappia includes a built-in env.php
template, but you can override this with a custom version.
🔧 Overriding with a Custom Secret
To use your own env.php, you can create a Kubernetes Secret manually and reference it in your values file.
Step 1: Create the Secret
Prepare your own env.php
file and create a Kubernetes secret:
IMPORTANT
The key name in your secret must be env-php.
kubectl create secret generic custom-magento2-env \
--from-file=env-php=./env.php
This creates a secret named custom-magento2-env
with a key env-php
containing your env.php
file.
Step 2: Reference the Secret in values.yaml
In your values.yaml, add:
magento:
existingEnvPHPSecret: custom-magento2-env
This tells the chart to use your custom-magento2-env
secret instead of the default generated one.
Environment Variables
TIP
You can use getenv
in your env.php
!
<?php
return [
'crypt' => [
'key' => getenv('MAGENTO_CRYPT_KEY'),
],
];
Making your own env variables
If you want to make more environment variables available to your env.php
, you can use a Secret to inject them into the container environment. This is particularly useful if you're managing secrets like database credentials or API keys.
kubectl create secret generic magento-sensitive-data \
--from-literal=MY_CUSTOM_KEY=value123 \
--from-literal=ANOTHER_SETTING=enabled
Making More Environment Variables Available to env.php
If you want to make more environment variables available to your env.php
, you can use a Kubernetes Secret
to inject them into the container environment. This is particularly useful if you're managing secrets like database credentials or API keys.
Step 1: Define Your Secret
Create a Kubernetes secret containing the additional environment variables:
kubectl create secret generic magento-custom-env \
--from-literal=MY_CUSTOM_KEY=value123 \
--from-literal=ANOTHER_SETTING=enabled
Step 2: Mount the Secret Using magento.envFrom
Update your values.yaml
to mount the secret as environment variables using the magento.envFrom
field:
magento:
envFrom:
- secretRef:
name: magento-custom-env
This will make MY_CUSTOM_KEY
and ANOTHER_SETTING
available to PHP as environment variables.
Notes
- Avoid storing secrets in plaintext. Use Secrets and access control policies. If you're using a infrastructure-as-a-service provider, strongly consider using their secret storage mechanisms like Azure Key Vault, AWS Key Management Service or Google Cloud Key Management