LycheeOrg/Lychee-Docker

[Updating version4.4.0 to 4.5.3] (docker) Error 500 No application encryption key has been specified.

jsaathof opened this issue · 13 comments

I am running the docker version of Lychee. I have upgraded Lychee from version 4.4.0 to version 4.5.3. Database migrations went well but I get a 500 error. No application encryption key has been specified. I have an application key in my .env file. I have thrown away the container and tried again. I see that there is a command cancelled.

It looks like the key is not generated because the application is in production. This was the case for the previous version but not for the new version. Does the script check the key or does it check the production status?

Below is the log output in docker.

[web]:~
root# docker logs lychee

-------------------------------------
  _               _                
 | |   _   _  ___| |__   ___  ___  
 | |  | | | |/ __|  _ \ / _ \/ _ \ 
 | |__| |_| | (__| | | |  __/  __/ 
 |_____\__, |\___|_| |_|\___|\___| 
 | |   |___/ _ __ __ ___   _____| |
 | |   / _' | '__/ _' \ \ / / _ \ |
 | |__| (_| | | | (_| |\ V /  __/ |
 |_____\__,_|_|  \__,_| \_/ \___|_|

-------------------------------------
Lychee Version: 4.5.3 (release)
Lychee Commit:  fe173e4
https://github.com/LycheeOrg/Lychee/commit/fe173e4b77ee81a204e0ca6064f37403ab03cec2
-------------------------------------
**** Make sure the /conf and /uploads folders exist ****
**** Create the symbolic link for the /uploads folder ****
**** Create the symbolic link for the /sym folder ****
**** Create the symbolic link to the old Lychee-Laravel folder ****
**** Copy the .env to /conf ****
**** Inject .env values ****
**** Generate the key (to make sure that cookies cannot be decrypted etc) ****
**************************************
*     Application In Production!     *
**************************************

Command Canceled!
**** Migrate the database ****
Nothing to migrate.
**** Check user.css exists and symlink it ****
**** Create user and use PUID/PGID ****
        User UID :      983
        User GID :      983
**** Set Permissions ****
**** Start cron daemon ****
Starting periodic command scheduler: cron.
**** Setup complete, starting the server. ****

I hope you can help me out.

Thanks,

Jurriaan

So I got a bit further. I removed the APP_KEY value from the .env file and started again.

[web]:~
root# docker logs lychee

-------------------------------------
  _               _                
 | |   _   _  ___| |__   ___  ___  
 | |  | | | |/ __|  _ \ / _ \/ _ \ 
 | |__| |_| | (__| | | |  __/  __/ 
 |_____\__, |\___|_| |_|\___|\___| 
 | |   |___/ _ __ __ ___   _____| |
 | |   / _' | '__/ _' \ \ / / _ \ |
 | |__| (_| | | | (_| |\ V /  __/ |
 |_____\__,_|_|  \__,_| \_/ \___|_|

-------------------------------------
Lychee Version: 4.5.3 (release)
Lychee Commit:  fe173e4
https://github.com/LycheeOrg/Lychee/commit/fe173e4b77ee81a204e0ca6064f37403ab03cec2
-------------------------------------
**** Make sure the /conf and /uploads folders exist ****
**** Create the symbolic link for the /uploads folder ****
**** Create the symbolic link for the /sym folder ****
**** Create the symbolic link to the old Lychee-Laravel folder ****
**** Copy the .env to /conf ****
**** Inject .env values ****
**** Generate the key (to make sure that cookies cannot be decrypted etc) ****
Application key set successfully.
**** Migrate the database ****
Nothing to migrate.
**** Check user.css exists and symlink it ****
**** Create user and use PUID/PGID ****
        User UID :      983
        User GID :      983
**** Set Permissions ****
**** Start cron daemon ****
Starting periodic command scheduler: cron.
**** Setup complete, starting the server. ****

But I still get the same error.

Yoi should be able to run php artisan key:generate to create a new key.

I am running in Docker. For me that should handle most is not all things. Running a command in the docker container is not how I see it should work. And I have been running a docker image of the previous version (4.4.0) which has been without issues. No need to run php commands.

And the key was generated as seen in my second attempt. However the launch page still gave me the 500 error. Even tried wiping all cached data and tried another browser.

The key mustn't be empt and it must be set to a random value in .env. You wrote that you removed it, then it won't work.

d7415 commented

I don't have time to look at this properly right now, but @jsaathof is correct:

The key mustn't be empt and it must be set to a random value in .env. You wrote that you removed it, then it won't work.

**** Generate the key (to make sure that cookies cannot be decrypted etc) ****
Application key set successfully.

Just to confirm, the error was "No application encryption key has been specified" both times?

The key was indeed set. I have emptied the key to see if something in the container would be done to fix this. But it has only regenerated a key for me. I have downgraded in the mean time (restored the database, run the older version in Docker) so I don't have the logs currently. But I haven't seen any other message than "500 - No application encryption key has been specified".

These are in the logs of the docker image.

127.0.0.1 - - [15/Aug/2022:15:50:48 +0000] "GET / HTTP/1.1" 500 1732 "-" "curl/7.84.0" "-"
192.168.20.6 - - [15/Aug/2022:15:51:14 +0000] "GET / HTTP/1.1" 500 1732 "https://admin.xenophobia.nl/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0" "192.168.20.159"

The docker ps output shows the container is unhealthy. That is the connection from localhost I guess.

[web]:~
root# docker ps
CONTAINER ID   IMAGE                                    COMMAND                  CREATED         STATUS                     PORTS                                                                                          NAMES
61f2261df178   lycheeorg/lychee:v4.5.3                  "/entrypoint.sh nginx"   2 minutes ago   Up 2 minutes (unhealthy)   0.0.0.0:8200->80/tcp, :::8200->80/tcp
...

And I see this when I open the browser.
Screenshot 2022-08-15 at 17 51 19

Hello,
First thanks for this great software.

I'm happy to see that there are still some new version coming.

I juste did an install of the version lycheeorg/lychee:v4.5.3 with docker.

I ran into the same error.

I was able to get around it by creating the APP_KEY entry with the following command. The entry was added to the .env file.

docker exec -it lychee /bin/bash
php artisan key:generate
I also had to create some folder into uploads to pass the test during the setup process.

d7415 commented

I was able to get around it by creating the APP_KEY entry with the following command. The entry was added to the .env file.

I'm glad that worked, but that's really weird. That command is run when the container starts (as shown in the logs above).

I also had to create some folder into uploads to pass the test during the setup process.

Thanks for that! It seems the installer wasn't updated when various folders were moved. I've opened LycheeOrg/Lychee#1473

Hi,

I have run the command inside the docker container. But as commented the command was run during the start of the container. So this did not fix my issue. Is there some information (logs or command output) I can provide to determine what the issue is?

d7415 commented

It seems like Laravel's doing something weird. Maybe try php artisan config:cache? Some users seem to report that's needed after generating a key (which still shouldn't have caused the initial problem because it was an existing key...)

I have issued the php artisan config:cache command and it seemed to have worked. I was thrown a "permission denied" on /var/www/html/Lychee/storage/logs/laravel.log which I ended up removing. After that the new Lychee version was presented. It works. Thanks for the help and thanks for this nice piece of software! Keep up the good work!

d7415 commented

Ah, thanks - I'll check the permissions on that log - I have a hunch.

I still don't know why that command would have worked, but I'm glad it did! I won't add it to the container for now, but at least we'll know if it happens again!