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

patressz's avatar

Laravel - digitalocean env problem

Hello guys, i have a problem with configuration laravel application under the docker and hosted on digital ocean.

I have a Dockerfile where i have defined necessary things and also ARG values.

# Dockerfile
# COPY ENV FILE
COPY ./.env.production .env

# Arguments
ARG DB_PASSWORD

# PRINT APPLICATION SECRETS TO .env
RUN echo "DB_PASSWORD=${DB_PASSWORD}\n"

i also have defined on digital ocean App-Level Environment Variables and after deploy everything is working fine, database connection etc, but then in routes/web.php i have defined endpoint for cron which trigger artisan command as i wrtie below.

Artisan::call('schedule:run');			

but after cron access this endpoint i get an error "Access denied for user 'myuser'@'10.40.6.1' (using password: NO)" in log file and i don't really know why. I also tried to clear config cache, but this does not help me.

When i hardcode DB_PASSWORD to .env.production files everything will start work as expected.

Thanks for any help :)

0 likes
1 reply
patressz's avatar
patressz
OP
Best Answer
Level 2

I already solved it. Problem was in that i have defined APP_ENV as a production, so laravel try to load the .env.production file if exists, where i didn't have defined some variables. Solve is simple, just rename .env.production to .env.prod or something else and all works as expected.

https://laravel.com/docs/10.x/configuration#additional-environment-files:~:text=Before%20loading%20your,will%20be%20loaded.

or check source code how laravel load the .env file. https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php

Please or to participate in this conversation.