I recently deployed a new Laravel project checked out directly from git. I figure out that the .env file is in gitignore and when application starts at the first request I get a 500 Internal Server Error because Laravel is unable to find the .env and the encryption key.
In my script I solved adding the following lines just before EXPOSE 8000:
COPY --chown=${USER}:${USER} .env.example .env
RUN php artisan key:generate
I don't know if this can be a good approach, but I think that if developers take care to synchronize the .env.example .env with all the configurations used to the application maybe works.
This is the error log:
2024-05-20 17:58:18 INFO Server running…
2024-05-20 17:58:18
2024-05-20 17:58:18 Local: http://0.0.0.0:8000
2024-05-20 17:58:18
2024-05-20 17:58:18 Press Ctrl+C to stop the server
2024-05-20 17:58:18
2024-05-20 17:58:19 2024-05-20 15:58:19,020 INFO success: octane_00 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-05-20 17:58:19 2024-05-20 15:58:19,021 INFO success: scheduler_00 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-05-20 18:00:42
2024-05-20 18:00:42 Illuminate\Encryption\MissingAppKeyException No application encryption key has been specified.
2024-05-20 18:00:42
2024-05-20 18:00:42 0 /var/www/html/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:79
2024-05-20 18:00:42 1 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/helpers.php:307
2024-05-20 18:00:42 2 /var/www/html/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:77
2024-05-20 18:00:42 2024-05-20 16:00:42,719 WARN exited: octane_00 (exit status 1; not expected)
2024-05-20 18:00:43 2024-05-20 16:00:43,721 INFO spawned: 'octane_00' with pid 620
I recently deployed a new Laravel project checked out directly from git. I figure out that the
.env
file is in gitignore and when application starts at the first request I get a 500 Internal Server Error because Laravel is unable to find the .env and the encryption key. In my script I solved adding the following lines just beforeEXPOSE 8000
:I don't know if this can be a good approach, but I think that if developers take care to synchronize the .env.example .env with all the configurations used to the application maybe works.
This is the error log: