How to set environmental variables in your .htaccess file

October 26, 2018

Setting env vars is easy in your .htaccess file.

SetEnv ENV_VAR_NAME 'env var value'

(you must enable mod_env in Apache for this to work)

You can access these environment variables in PHP with this code:

var_dump(getenv('ENV_VAR_NAME'));