1
votes

I've uploaded my Laravel app to a cpanel host . The problem is that Laravel does not read the contents of the .env file and show me a "Whoops, looks like something went wrong." page ( twice In one page ) This error is displayed because the program can not receive the APP_KEY variable . can not read .env file at all . I searched a little for this problem, but the solutions did not work . I tried all these:

  • 'php artisan cache:clear' command
  • 'php artisan config:clear' command
  • 'php artisan config:cache' command
  • change permission for .env file (755)
  • run all 'composer update' , 'composer install' , 'composer dump-autoload' commands
  • I did not use env function anywhere
  • There are no spaces in the values stored in the env file

But none of the above did not work out. However, My program runs well in local ( windows ) and there is no problem But it does not run on the server ( cpanel )

note : I realized that when I execute the 'php artisan config:cache' command on server , all cache files are made in 'bootstrap/cache' folder, except for the config.php file note2 : I uploaded several times in different ways. Once all the files in the folder in the root and the public files in the public_html folder . and once all the files in the public_html folder. Both not working

Does anyone know where the problem is?

in this time i put all my app files in public_html folder

3
How have you uploaded it to cPanel, What is the file structure? I assume you have the contents of your public folder now inside the public_html folder and the rest of your files in the root folder?Colin Barstow
I uploaded several times in different ways. Once all the files in the folder in the root and the public files in the public_html folder . and once all the files in the public_html folder. Both not workingHossein Mokhtari
APP_KEY is first set in .env and read in config/app.php.zeros-and-ones
post screen shot of your file treezeros-and-ones
As I said, the problem is not app key at all. The problem is that the .env file is not read. I can set app key in config.php directly . but i want to know why .env file not working . +this is not a real project this is a test on cpanel .Hossein Mokhtari

3 Answers

1
votes

Take a look at the storage/logs/laravel.log file to get more accurate information.

Make sure the putenv() and getenv() functions are not disabled In php.ini

0
votes

You should not use .env file for production, it is only for development purpose.

Create environment variables for your production(on server not .env).

-1
votes

That always happens to me on new sites, so I usually run:

chmod 777 storage/ storage/app/ storage/framework/ storage/logs/
chmod 777 storage/ storage/app/ storage/framework/ storage/logs/
chmod 777 storage/framework/cache/ storage/framework/sessions/ storage/framework/views/
chmod 777 bootstrap/cache/
chmod 777 bootstrap/cache/*
chmod 777 storage/logs/laravel.log

Note: The last one (laravel.log) does not exist the first time, bun then it is created.

Instead of 777 you could use a more recommended ug+rwx if you first run: chgrp -R www-data storage bootstrap/cache chgrp -R www-data storage storage

where www-data is the web server user, it could be apache or httpd