According to 12 factor app, the best way to configure things for deployment is through environment variables, not necessarily environment variable files, but just any environment variables. The problem is how to get environment variables into PHP. It is quite complicated depending on what you're doing.
The first step is to make sure you're using getenv
in PHP for environment variables as the $_ENV
array may not be set unless you set variables_order=EGPCS
in the INI settings. This is enough for command line PHP applications including the command line PHP server.
If you're running PHP through Apache either via mod_php or CGI, the only way is to use an .htaccess
file along the path from the index.php
to the document root and to use SetEnv NAME Value
directives. Or you put them into the Virtual Host block inside Apache configuration.
If you're using NGINX + PHP-FPM. You have 3 options: