dongyi7901
2018-05-09 21:29
浏览 779
已采纳

Laravel不会在面板中读取.env文件

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

图片转代码服务由CSDN问答提供 功能建议

我已将Laravel应用程序上传到cpanel主机。 问题是Laravel没有读取.env文件的内容并向我显示“哎呀,看起来出了问题。” 页面(两次在一页中) 显示此错误是因为程序无法接收APP_KEY变量。 根本无法读取.env文件。 我搜索了一下这个问题,但解决方案没有用。 我尝试了所有这些:

  • 'php artisan cache:clear'command
  • 'php artisan config:clear'command
  • 'php artisan config:cache'command
  • 更改.env文件的权限(755)
  • 运行所有'composer update','composer install ','composer dump-autoload'命令
  • 我没有在任何地方使用env函数
  • env文件中存储的值中没有空格

    但以上都没有解决问题。 但是,我的程序在本地(Windows)运行良好并且没有问题但是它不能在服务器上运行(cpanel )

    注意:我意识到当我在服务器上执行'php artisan config:cache'命令时,所有缓存文件都在'bootstrap / cache'文件夹中生成,但配置除外。 php文件 note2:我以不同的方式上传了几次。 一旦根文件夹中的所有文件和public_html文件夹中的公共文件。 以及public_html文件夹中的所有文件。 两者都不起作用

    有谁知道问题所在?

    在这个时候我将所有的app文件放在public_html文件夹中

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doudui1850 2018-05-13 17:59
    已采纳

    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

    点赞 打赏 评论
  • dongzhuo6137 2018-05-10 05:35

    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

    点赞 打赏 评论
  • dqfr90979 2018-10-24 05:57

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

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

    点赞 打赏 评论

相关推荐 更多相似问题