Hi @nathanmartin , ok just for my understanding: you can just use these environment variables for the build and you cannot let netlify create a file on the project with the environment variable name and value written into it, so that we can use it in PHP and for example show it?
Netlify won’t deploy a PHP file that can be accessed at runtime.
It must not be a PHP file, a simple file without any extension would be enough.
I just need to access the values after the build. So the values simply need to be stored into a file.
@eduard.f I’m a little confused by what you’re doing, but it should work.
If you’re ultimately putting a value into an environment variable then writing it into a file and deploying it, you could cut out the middle man and just write it directly into the file.
@nathanmartin I need to deploy the same project multiple times, the only difference is one variable being different. With this variable we control which of our API’s should get loaded.
For example we have one Production API and one Staging API.
However my supervisor wants to only use one branch so the only possibilty is to set the API Url by a netlify variable. So I just need netlify to write a environment variable value into a file.
I’m just confused if the two occurrences will be running on Netlify, or if they’ll be running elsewhere and loading a file from Netlify.
However regardless, if you’re going to be creating two site instances in Netlify, both pointing at the main branch, and then configuring each one with different environment variables, that’s absolutely possible.
I’ve used it previously to produce 5 x different locale versions of a site, all from the same main branch.
You can do this using any of the languages available at build time, or as that example shows just using the redirection operator to directly write to a file in linux via the build command.
In that instance it’s writing to a folder of public/ so you would want to make sure that your Build configuration sets the Publish Directory correctly, so the file ends up where you want it to.