CodeIgniter Forums
How to store multi line config in .env? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to store multi line config in .env? (/showthread.php?tid=75987)



How to store multi line config in .env? - vmulber - 04-04-2020

How to store a multi line key in the .env file

publicKey = <<<EOD
-----BEGIN PUBLIC KEY-----
ZZzzZZZZZzZZzzzZZZZZZZZZZzZzZZJBZZZlzGDzCzzZZZZzZzZzzzzzzzzzzZZZZ
M9NYvZZZZZzzz/ZZZZZZZZZoDShgMTGirZZZzzzzzZzzZ/EypXBPHQ08CZzZZZZ==
-----END PUBLIC KEY-----
EOD;


RE: How to store multi line config in .env? - dave friend - 04-04-2020

It doesn't look like it is possible. First off, the .env file is processed on a line-by-line basis and unless the line has an equal sign (=) it isn't considered to hold any information about a variable. Second, .env is not a PHP file and so will not be considered by the PHP parser meaning that the heredoc syntax won't be evaluated to the string you need.

In the case of storing an encryption key, I don't think the line breaks are a MUST, so you could try it out as one long line of text without line breaks. See if that's useable by the encryption functions you're using.


RE: How to store multi line config in .env? - vmulber - 04-04-2020

(04-04-2020, 09:01 AM)daveĀ friend Wrote: It doesn't look like it is possible. First off, the .env file is processed on a line-by-line basis and unless the line has an equal sign (=) it isn't considered to hold any information about a variable. Second, .env is not a PHP file and so will not be considered by the PHP parser meaning that the heredoc syntax won't be evaluated to the string you need.

In the case of storing an encryption key, I don't think the line breaks are a MUST, so you could try it out as one long line of text without line breaks. See if that's useable by the encryption functions you're using.


You are correct on your suggestion.

I was pretty tired last nite when I was working on this, and was too tired to try any more, but I just tried your suggestion and it worked perfectly.



jwt.publicKey = "-----BEGIN PUBLIC KEY----- MFwwDQH...Q08CAwEAAQ== -----END PUBLIC KEY-----"



thanks for the help on this.