mstnorris's avatar

App Key?

I appreciate that this may be a stupid question but what is the App Key used for and how should it be used... where and when ?

When I run the command artisan key:generate locally it saves it to the .env file, should I then copy the environment variable to my Forge installation?

0 likes
16 replies
bestmomo's avatar
Level 52

App Key is used for all encrypted data, like sessions.

.env is the good place for it.

4 likes
mstnorris's avatar

I thought that is what it is used for, so am I correct then in copying it to my Forge installation?

bestmomo's avatar

I dont use Forge but it's a server and you need to copy your .env in your installation.

Btw Artisan creates the key in config.app.php, not directly in .env.

mstnorris's avatar

I'm using Laravel 5 and that that may have changed recently, as when I run artisan key:generate my .env file was automatically updated :)

Thanks for your help.

1 like
bestmomo's avatar

You're right, I wasn't with the last commit, it sets directly in all .env and also in config/app.php.

1 like
MladenJanjetovic's avatar

I cloned my app in another location, and ran artisan key:generate and got some other app key. But my passwords, created by Hash::make(), are still working. I thought that this key is used in Hash::make and that new key will make old passwords unusable. Am I missing something?

3 likes
krisi_gjika's avatar

@MladenJanjetovic app key is not used to hash passwords. It is used for encrypting data, sessions, etc, which is different from hashing.

1 like
theUnforgiven's avatar

I always copy it over or just creat a new one on Forge directly from CLI

akselon's avatar

Could some one anwser @Youndivian ? Should old passwords still be working after I change the app key? And one more thing. Should I use the same app key on local env as on the serwer?

1 like
pmall's avatar

App key has nothing to do with hashing passwords, it is used to encrypt sessions.

1 like
lindstrom's avatar

@akselon @Youndivian Passwords are hashed using bcrypt and do not rely on the app key or anything else so they will work fine (see: \vendor\laravel\framework\src\Illuminate\Hashing\BcryptHasher.php).

As for Forge, log in and navigate to your server and click the icon under Manage. Then choose the tab labeled Environment and click the button labeled Edit Environment. Paste your varables into the overlay and click save. Your changes will be saved as a .env to your project's root. I can't think of any reason to use a different app key, but it is only material to the app that uses it (i.e. prod/dev/etc).

2 likes
pmall's avatar

I can't think of any reason to use a different app key

Yes but they can be different, it doesnt matter. I just use php artisan key:generate when I install my apps somewhere and thats all.

2 likes
alexreynolds's avatar

I feel strongly about it and love finding out more about it. If you could, as you learn more, would you mind adding more information to your blog

Please or to participate in this conversation.