Hello everyone, I have a big problem, my hard drive crashed and I lost all my data. After changing my hard drive, I cloned my Strapi Next.js project but Strapi won’t launch with an error on the APP KEYS that I no longer have. How can I recover my Strapi admin? Thank you all.
You will need to create your .env file if it’s a fresh project cloned down.
You just create random strings for the different values there should be an .env.example file you can look at in the project unless you deleted it
Just so it’s a bit clearer for future searchers, as I ran into the same problem.
Create an .env file in the base directory of the project.
Add these values to it:
APP_KEYS={random-string-doesn’t-matter}
API_TOKEN_SALT={random-string-doesn’t-matter}
Hi, thanks for the solution. I have some comments that could improve the user experience though.
Couldn’t the .env file be automatically generated?
If not, it would be great to have an explanation on the terminal of what the user is supposed to do (create the .env file). Or at least a link to a strapi url that explains it. Having to copy the error, and paste it in google to find a solution is not a good user experience.
Also the explanation should be in the readme.md, as it will be quite common for developers working on the repo/project to run against this issue.
Hi @brsastre glad for the feedback
Just to let you know, the env file is auto-generated when using the CLI tool not cloning it down. (you want to use the CLI tool to create your project). The user here had cloned down their own repo meaning the .env would not exist as it’s not to be committed to github.
Hi @Eventyret thank you for your feedback.
I think it would be quite common for more than one developer to be working on a strapi project. Suppose I created my strapi project with no problems, and I push the repo to github. Then developer-2 clones the repo and wants to start working on it.
Create a .env file there should be an .env.exmaple that is committed.
And depending on your database if you are using sqlite for development then they only need to run yarn install or npm install then run it.
@Eventyret Are these APP_KEYS and API_TOKEN_SALT? So, should they be committed to the remote repository or not?
If you have a continuous deployment setup, you want this file to be there already, but you also don’t want to commit sensitive info.
The alternative would be to specify these environment variables in the pm2 configuration file, if you’re doing that, assuming this works (i.e. you just need to export these environment variables and it does not matter if this is done in the .env or somewhere else).
Moreover, I am in the process of migrating a Strapi 3.6.11 to Strapi 4.15. An APP_KEYS and API_TOKEN_SALT was generated at some point. Do I need to use this specific one in production or maybe this is not necessary?
So i’m having this same exact issue. I have a .env file with my APP_KEYS set (plus many other env variables set) – but i still get this issue you are talking about. What am i doing wrong?
I’m doing a docker build -t app-name . and then docker run -d -p 1337:1337 app-name