I have a symfony skeleton project, and I use the .env file for storing the environment variables.
Inside the Dockerfile, I run composer install, but it creates a .env file. From my pipeline environment variables I want to edit the .env file. What is the best approach to do that?
Delete the .env and create my own? Or is there a way to edit the .env file?
You can use bash redirection to append values to your .env file.
echo ENV_VARAIBLE=value > .env - Use this if .env doesn't exist, (op.a. it overwrites existing .env)
echo ENV_VARIABLE_2=value2 >> .env - Use this to append variable to existing .env file.
More: https://unix.stackexchange.com/questions/89386/what-is-symbol-and-in-unix-linux
A lot more: http://www.catonmat.net/blog/bash-one-liners-explained-part-three/
Related
When I do git push to the project without put .env to .gitignore file the project work fine and load the env variables but when put .env in .gitignore file and do git push and add env variables to project setting and redeploy the project in this case vercel not load env variables.
UI Setting env variables
I don't know why ?
any suggestions please !
Nextjs wants you to use a .env.local file to store env vars.
Prisma uses .env
If I use a .env.local file then setting up the Prisma db
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
I get a DATABASE_URL does not exist error.
What's the right way to set up env vars for a Prisma, Nextjs, Vercel app?
You can use dotenv-cli to force loading specific environment file.
1- Install dotenv-cli package
2- create script to run env before prisma migration on your package
"scripts": {
...
"prismaDev": "dotenv -e .env.local prisma migrate dev ",
}
3- now you can simply run npm run prismaDev
You can load environment variables with process.env.DATABASE_URL in your case and you can leave it in .env as Prisma asks for. Nextjs can handle multiple .env files without any extra effort.
No need to use an extra package, Nextjs will handle the env vars for you.
https://nextjs.org/docs/basic-features/environment-variables
You can leave the standard setup and use the created .env file (by the prisma cli:
https://www.prisma.io/docs/getting-started/setup-prisma) and add your connection string.
the rest is magically handled by next.
Be sure to follow the instructions (manual or cli pointers) regarding gitignore and such..
To reiterate: both can live next to each other! Check the next documentation for load order if it matters. (see link above)
How do I specify array values for Ghost's .env file?
I am using a .env file to configure Ghost. Per How to define array/object in .env file? I have set up a line in my .env which reads:
logging__transports="file,stdout"
However Ghost fails with:
TypeError: this.transports.splice is not a function
How do I specify arrays in .env files for Ghost?
Ghost now supports this:
logging__transports='["file", "stdout"]'
I am putting my website in production, but I have a problem with the environment.As you can see in the screenshot below, the site remains in "dev" mode
However, I already modify my .env file as follows:
APP_ENV=prod
APP_DEBUG=0
APP_SECRET=secretthings
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
should I change another file or do something else so that my site is finally operational?
Thank you for your answers
Did you try to clear your cache?
Move to your project and type php bin/console cache:clear. You can also pass the enviroment you want to clear with php bin/console cache:clear --env=prod. Use dev or prod as your parameter.
Edit: If you have a .env.local file - you need to change your enviroment there.
After you update your .env file you should run composer dump-env prod to compile your environment file for production use.
When I run composer install for my symfony project, my .env file is rewrote by new generated one. What should I do to save my .env intact?
Applications created after November 2018 had a slightly different system, read changes
From the official documentation
.env.local : defines/overrides env vars for all environments but only in your local machine
.env : defines the default value of env vars.
The .env and .env.<environment> files should be committed to the shared repository because they are the same for all developers. However, the .env.local and .env.<environment>.local and files should not be committed because only you will use them. In fact, the .gitignore file that comes with Symfony prevents them from being committed.