How do I specify arrays in .env files for Ghost? - ghost-blog

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"]'

Related

How to set environment variables with Prisma, Nextjs, and Vercel

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)

PhpStorm SCSS file-watcher creates duplicates

I recently added a SCSS file-watcher in PhpStorm and generally it does what it is suppose to. The only issue I have is that it creates a new folder within the sass-folder everytime it synchronizes. The new folder doesn't have a name but it includes the files of the sass-folder.
These are the settings of the file watcher:
Scope:
The sass-folder
Arguments:
--style expanded --no-cache --update $FileName$:../css/$FileNameWithoutExtension$.css
Output paths to refresh:
../css/$FileNameWithoutExtension$.css:.../css/$FileNameWithoutExtension$.css.map
Is there something wrong with the settings?
There are 3 dots in the output path. Change it to:
../css/$FileNameWithoutExtension$.css:../css/$FileNameWithoutExtension$.css.map

composer rewrites my .env file by new generated one

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.

Edit env file in pipeline

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/

How can I use the Container's ENV on DATABASE_URL Symfony

I have the following environment on my php container like so:
DATABASE_URL:mysql://root:${MYSQL_ROOT_PASSWORD}#db:3306/${MYSQL_DATABASE}
I tried to echo it inside my container, and do a db migration. All is good. Now I used it on my .env file on symfony like so:
DATABASE_URL=${DATABASE_URL}
When i tried to login, the app says:
Authentication request could not be processed due to a system problem.
When i try to manually put everything on .env DATABASE_URL all is good.
I suspect that when I tried to use the container's ENV it doesn't get it right.
My question is how can I use the actual Containers' environment variable?
Thanks!
Note:
I on dev environment.
I am not quite familiar with symfony, but it seems like symfony never overwrites existing environment variables. (Ref: https://symfony.com/doc/current/components/dotenv.html)
What if you remove that line in your .env file? Since DATABASE_URL is already an environment variable, calling getenv('DATABASE_URL') in symfony should return you the correct value even if you did not define it in .env. All dotenv does it to write those key value pairs as environment variables in your system. You don't need to define it again if it is already present.
note that there is separate environments when you run php from cli and when it gets run by webserver (when you access it from your browser).
For example, in case of nginx-fpm, the variables that you see in your cli by running printenv are not avaiable in php script run by nginx when you call getenv(). In order to set environment variable for php fpm you can edit php-fpm.conf:
....
[www]
env[DATABASE_URL] = 'mysql://...'
....
If you use another webserver than you should find out how to make env vars available in php script.
Your DATABASE_URL=${DATABASE_URL} in .env file didn't work bacause DATABASE_URL was not set for php fpm.
Hope this helps.
P.S. Note, that this construction VAR=${VAR} makes nothing because DotEnv will not override VAR as it is already defined.
P.P.S. It is advised that you use .env file for your dev server and "real" env variables in staging/production.

Resources