Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara28580's avatar

Generate App key in production with envoyer

I am trying to generate a new app key with a deployment hook in envoyer but it seems it has no effect. Someone knows how to do it?

0 likes
18 replies
LaryAI's avatar
Level 58

You can generate a new app key with a deployment hook in Envoyer by using the artisan key:generate command. To do this, you will need to add a new hook to your Envoyer deployment.

  1. Log into your Envoyer account and select the project you want to add the hook to.
  2. Click on the "Hooks" tab and then click the "Create Hook" button.
  3. Select the "Artisan" option from the dropdown menu.
  4. Enter the command artisan key:generate in the "Command" field.
  5. Select the "After Deployment" option from the "When to Execute" dropdown menu.
  6. Click the "Create Hook" button.

Your new hook should now be added and will generate a new app key with each deployment.

1 like
Sinnbeck's avatar

Why generate a new key? It will destroy all session data, as the key is used to decrypt it

1 like
lara28580's avatar

@Sinnbeck Because I had that key in dev so thought it would be good to generate a new one.

Sinnbeck's avatar

@SmokeTM But the key is something you do when you set up the server with the project the very first time. Not a deployment thing. So just ssh into the server now and generate a new one

1 like
lara28580's avatar

@Sinnbeck Where do I have to execute this command in the current folder or somewhere in the releases subdirectories?

lara28580's avatar

@Sinnbeck If I execute the command in the current folder the key in my envoyer env file stays the same.

Sinnbeck's avatar

@SmokeTM Ok I have never used envoyer, but I am confused why it needs an env file? What is that used for?

lara28580's avatar

@Sinnbeck It looks like the .env file in forge but it is encrypted as well. So you can only access it with a password.

Sinnbeck's avatar

@SmokeTM Ok. Sadly I cannot find any documentation at all for how that is supposed to work. I will let someone else why uses the service answer. I assume you somehow specified the env file on the site and now need to edit it as its copied only the server in a new deployment.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@SmokeTM So once the file is made in there you can never edit it again? If you can, you can just grab a new key from local and paste in

php artisan key:generate --show

This will give you a key but it wont chance the key locally

2 likes
lara28580's avatar

@Sinnbeck It is possible to edit the file but I thought there is an envoyer way so the speak :) Thanks

Please or to participate in this conversation.