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

ozoriotsn's avatar

Unable to set application key. No APP_KEY variable was found in the .env file.

Hi, my problem when creating a new project with laravel 9 in a docker container with PHP 8.1.13

composer create-project laravel/laravel example-app When running the above command I get this error:

Unable to set application key. No APP_KEY variable was found in the .env file.

.env.exemple and .env files are created in the directory, but the key is not automatically added to the APP_KEY variable the APP_KEY= variable is also created empty I already tried running this command, but it didn't work:

php artisan key:generate Unable to set application key. No APP_KEY variable was found in the .env file

php artisan key:generate --show base64:vRdsPl8qp/adnMpzkpSGrkOewAgGXVJBugL+r0M1gZ8=

php artisan config:cache php artisan config:clear

0 likes
6 replies
cwhite's avatar

What does your .env_example look like

ozoriotsn's avatar

APP_NAME=Laravel 
APP_ENV=local                
APP_KEY=                     
APP_DEBUG=true      
APP_URL=http://localhost
                             
LOG_CHANNEL=stack    
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug      
                   
DB_CONNECTION=mysql     
DB_HOST=127.0.0.1    
DB_PORT=3306            
DB_DATABASE=laravel  
DB_USERNAME=root     
DB_PASSWORD=            
                    
BROADCAST_DRIVER=log 
CACHE_DRIVER=file       
FILESYSTEM_DISK=local   
QUEUE_CONNECTION=sync
SESSION_DRIVER=file 
SESSION_LIFETIME=120                 
                            
MEMCACHED_HOST=127.0.0.1             
                            
REDIS_HOST=127.0.0.1  
REDIS_PASSWORD=null                  
REDIS_PORT=6379             
                                 
MAIL_MAILER=smtp                     
MAIL_HOST=mailhog                    
MAIL_PORT=1025              
MAIL_USERNAME=null  
MAIL_PASSWORD=null                   
MAIL_ENCRYPTION=null        
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"     
                                 
AWS_ACCESS_KEY_ID=                     
AWS_SECRET_ACCESS_KEY=           
AWS_DEFAULT_REGION=us-east-1           
AWS_BUCKET=                          
AWS_USE_PATH_STYLE_ENDPOINT=false              

PUSHER_APP_ID=                       
PUSHER_APP_KEY=             
PUSHER_APP_SECRET=                   
PUSHER_HOST=                         
PUSHER_PORT=443             
PUSHER_SCHEME=https                  
PUSHER_APP_CLUSTER=mt1           
                                 
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"      
VITE_PUSHER_PORT="${PUSHER_PORT}"      
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

1 like
ozoriotsn's avatar

Hi, my problem was my docker-compose config env_file, it was generating conflict and giving the error. env_file: - .env

azbx's avatar

@ozoriotsn

that would not solve your problem

you can have conflicting configs but down the line its gonna cost you.

what you need to do is run this.

php artisan key:generate

azbx's avatar

@ozoriotsn you could run this in the console to fix that

php artisan key:generate

1 like
ozoriotsn's avatar

My problem was a conflict with my docker .env that made a copy, generating this error

/projects/client/docker/.env
/projects/client/docker/html/laravel/.env

shell script copy /projects/client/docker/.env to /projects/client/docker/html/laravel/.env generating error

Solution:

remove /projects/client/docker/.env
php artisan config: clear
php artisan config: cache
php artisan key: generate

success

5 likes

Please or to participate in this conversation.