Chapters
29 Chapters
|
3:14:24
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
22.
Secrets Management Setup
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.3.0",
"ext-iconv": "*",
"antishov/doctrine-extensions-bundle": "^1.4", // v1.4.2
"aws/aws-sdk-php": "^3.87", // 3.110.11
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.1
"doctrine/doctrine-bundle": "^2.0", // 2.0.6
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // 2.1.2
"doctrine/orm": "^2.5.11", // v2.7.2
"doctrine/persistence": "^1.3.7", // 1.3.8
"easycorp/easy-log-handler": "^1.0", // v1.0.9
"http-interop/http-factory-guzzle": "^1.0", // 1.0.0
"knplabs/knp-markdown-bundle": "^1.7", // 1.8.1
"knplabs/knp-paginator-bundle": "^5.0", // v5.0.0
"knplabs/knp-snappy-bundle": "^1.6", // v1.7.0
"knplabs/knp-time-bundle": "^1.8", // v1.11.0
"league/flysystem-aws-s3-v3": "^1.0", // 1.0.23
"league/flysystem-cached-adapter": "^1.0", // 1.0.9
"league/html-to-markdown": "^4.8", // 4.8.2
"liip/imagine-bundle": "^2.1", // 2.3.0
"nexylan/slack-bundle": "^2.1", // v2.2.1
"oneup/flysystem-bundle": "^3.0", // 3.3.0
"php-http/guzzle6-adapter": "^2.0", // v2.0.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.4
"sensio/framework-extra-bundle": "^5.1", // v5.5.3
"symfony/asset": "5.0.*", // v5.0.2
"symfony/console": "5.0.*", // v5.0.2
"symfony/dotenv": "5.0.*", // v5.0.2
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "5.0.*", // v5.0.2
"symfony/framework-bundle": "5.0.*", // v5.0.2
"symfony/mailer": "5.0.*", // v5.0.2
"symfony/messenger": "5.0.*", // v5.0.2
"symfony/monolog-bundle": "^3.5", // v3.5.0
"symfony/property-access": "4.4.*|5.0.*", // v5.0.2
"symfony/property-info": "4.4.*|5.0.*", // v5.0.2
"symfony/security-bundle": "5.0.*", // v5.0.2
"symfony/sendgrid-mailer": "5.0.*", // v5.0.2
"symfony/serializer": "4.4.*|5.0.*", // v5.0.2
"symfony/twig-bundle": "5.0.*", // v5.0.2
"symfony/validator": "5.0.*", // v5.0.2
"symfony/webpack-encore-bundle": "^1.4", // v1.7.2
"symfony/yaml": "5.0.*", // v5.0.2
"twig/cssinliner-extra": "^2.12", // v2.12.0
"twig/extensions": "^1.5", // v1.5.4
"twig/extra-bundle": "^2.12|^3.0", // v3.0.1
"twig/inky-extra": "^2.12", // v2.12.0
"twig/twig": "^2.12|^3.0" // v2.14.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.3.0
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/browser-kit": "5.0.*", // v5.0.2
"symfony/debug-bundle": "5.0.*", // v5.0.2
"symfony/maker-bundle": "^1.0", // v1.14.3
"symfony/phpunit-bridge": "5.0.*", // v5.0.2
"symfony/stopwatch": "4.4.*|5.0.*", // v5.0.2
"symfony/var-dumper": "5.0.*", // v5.0.2
"symfony/web-profiler-bundle": "4.4.*|5.0.*" // v5.0.2
}
}
30 Comments
Hi, what is the difference between putting application-wide parameters in the top section <b>parameters:</b> of the <b>services.yaml</b> file, and putting them as you did there under
This is how I currently do it
1) In the .env file define for example a variable called <b>basepath</b>
2) In services.yaml I do this:
class EntryController extends AbstractController
{
4) To actually get one of the variables inside a function, I then do this:
$basepath = $this->globalParameters->get('basepath');IS there just an easier way to do this now, where I can put all app-wide variables under that <b>bind:</b> section and just pass them as an argument to my controller functions?
Hey Mattias,
Using the bind key is just for convenience when a parameter will be used in many places.
I wouldn't inject the ParameterBag, I'd only inject the parameter that I need:
Cheers!
Oh, but I use my parameters in normal controllers, not in services.
Is my way the correct way of doing it then? Since all of my controllers aren't defined as services at all.
Are you sure your controllers are not services? That's the default since Symfony 4.4, if you can inject services into your controller's arguments, then they are defined as services. I don't usually inject parameters into my controllers, what I usually do is inject the parameter directly into the service that's going to use it. But, if for some reason you're going to use it in a controller, then you can do precisely what you did or just add a new bind key
Cheers!
Hi there, I managed to create a first secret for the prod env, but when I try to set a second, it just raise an error:
Fatal error: Symfony\Component\DependencyInjection\Exception\ParameterCircularRe<br />ferenceException: Circular reference detected for parameter "env(base64:default:<br />:SYMFONY_DECRYPTION_SECRET)" ("env(base64:default::SYMFONY_DECRYPTION_SECRET)" ><br /> "env(default::SYMFONY_DECRYPTION_SECRET)" > "env(SYMFONY_DECRYPTION_SECRET)" ><br />"env(base64:default::SYMFONY_DECRYPTION_SECRET)"). in C:\laragon\www\DESmdc\vend<br />or\symfony\dependency-injection\Container.php:389Any clue ?
Hey picks!
Ah, circular reference!
Let's... see if we can figure this out ;). It looks like, somehow, you have a parameter that is referencing itself. If you follow the error message, it looks like eventually Symfony sees that the
SYMFONY_DECRYPTION_SECRETenvironment variable is set toenv(base64:default::SYMFONY_DECRYPTION_SECRET)"), which then causes a loop.Can you post the contents of all of the relevant files? Like .env, .env.local, services.yaml (if you have anything relevant there)?
Cheers!
Sure!
My .env file has:
I don't use a .env.local for now as I don't need to override anything
And in my services.yml I have many declarations of env parameters (which some are supposed to be stored in the secret vault) like :
Hello, any news on this subject? I am facing the same problem (<b>php 7.3.5</b>).
I was able to add a first variable in <b>PROD</b>, but when I wanted to edit it, I got the same error.
I also do not have the environment variable "
SYMFONY_DECRYPTION_SECRET", I did not manage to generate it. When I tried the command :php -r 'echo base64_encode(require "config/secrets/prod/prod.decrypt.private.php");':I got this error
Parse error: syntax error, unexpected 'private' (T_PRIVATE) in Command line code on line 1Hi Kiuega this has been fixed and merged into SF3.4 apparently => https://github.com/symfony/...
Hey ! (ami Français), On SF 4 and 5, there seems to be nothing. No update available for recipes, it's strange.
On the other hand, did you end up succeeding in generating the environment variable
SYMFONY_DECRYPTION_SECRET?EDIT : Nicolas Grekas said that it was OK, and that we will just have to wait for the 5.1.3 release
Just saw that yes Kiuega ;) Thanks! In the meantime I could make it work by hardcoding SYMFONY_DECRYPTION_SECRET in my .env prod file with its encoded value...
Good work around! The Pr has been merged, but not tagged yet. I would expect a tag fairly soon, as the last one was 3 weeks ago.
Cheers!
Hey picks!
Hmm. I don't see
SYMFONY_DECRYPTION_SECRETanywhere in these files? Where/how are you setting this?To give you a bit more context, the default value of the "decryption environment value" is
base64:default::SYMFONY_DECRYPTION_SECRET. What I mean is, when Symfony tries to decrypt your fault, it looks for thisSYMFONY_DECRYPTION_SECRETenvironment variable , then "base64 decodes" it. It almost looks like theSYMFONY_DECRYPTION_SECRETvalue is set to itselfSYMFONY_DECRYPTION_SECRET... or something similar.Cheers!
I have no idea, I don't remember setting this value anywhere in my project!
I this something that needs to be done?
Hey picks
Yes, you whether set that env variable up or you ensure that the file
config/secrets/prod/prod.decrypt.private.phpexists in your project. If that's not the case, double check your env vars and parameters to see if something is trying to use theSYMFONY_DECRYPTION_SECRETenv var.Cheers!
Hi MolloKhan,
If I do a project search for "SYMFONY_DECRYPTION_SECRET" within PhpStorm, it only find references in the cache...
This env is not set anywhere in my project, and I have generated a config/secrets/prod/prod.decrypt.private.php (that's how I managed to generate the first secret, but not the second...). This is weird, really.
So even weirder, if I manually set a SYMFONY_DECRYPTION_SECRET env var within my .env.prod.local file, it now works!!! But I still have my config/secrets/prod/prod.decrypt.private.php...
I'm lost.
That's weird :)
What Symfony version do you have?
MolloKhan I was using a solid 4.4 version at the start of the project, then I upgraded it to 5.0 and 5.1... Maybe it is missing a package or something?
I have the same problem with a second project now! I downloaded a fresh copy of SF5.1 and installed the latest packages I needed, adapted and copied the "old" files(aseets, src, templates, config...), and it did the exact same : first prod secret is generated, second one raises the issue. Unless I add the SYMFONY_DECRYPTION_SECRET env var in my .env.prod.local file... This is insane.
Hey picks!
Yea, this sounds SUPER weird, so I'm checking into it further. So far, I can't repeat the error - I must be missing something that you have. Here's what I've tried so far:
1) I started a new project, and tried to create 2 secrets:
Both secrets were created without any problems.
2) I downloaded the course code from this page, unzipped it, and moved into the "finish" directory. Then I:
Again, this had no problems.
Am I doing something different than you are? I assumed that you're getting the error right when you call secrets:set for the 2nd secret, is that correct? Or do you get the error at some other point?
Let me know!
Cheers!
weaverryan yes that's correct, that's only occuring for the 2nd secret... I'll try to set a blanck copy like you did to see if has something to do with my local dev environment... and let you know! Thanks as always.
Awesome! Let me know what you find out! It definitely sounds "fishy", but I can't repeat it :/
weaverryan the issue has been raised at SF, it seems like it is indeed a bug ==> https://github.com/symfony/...
Hey picks!
Great! I mean, not great having a bug... of course :). But at least we know others have the issue and there will be an effort to fix it. I just "pushed" on that PR to try to keep it moving. It's interesting that, on that issue, some people are able to repeat and others cannot. What version of PHP are you on? If we could identify the reason why it happens on some machines but not others, that could help a lot. I tried on PHP 7.4 (and did not get the bug).
Cheers!
weaverryan I am the one saying he his using PHP 7.2 ;)
Come on picks! Where is your brand consistency? :p Ok, when I hover over picks44, I can see VinZ :D
Btw, I see you're from Nantes! We visited there years ago - after the last SymfonyCon in Paris - lovely place - saw the machines de l'île of course ;)
weaverryan haha yes, cool! You should consider participating to the "web2day" event, it is quite big now, and there are lots of conferences dedicated to tech ;) could be awesome.
PS: I registered on Disqu's using FB login, that's why!
4:30 — there is dd() function for this. ;)
Hey TomaszGasior
Yep you are totally right, you can use
dd()for it, since Symfony 4.1.Cheers!
"Houston: no signs of life"
Start the conversation!