如何在Laravel中保护.env文件 [英] How to protect .env file in Laravel

查看:78
本文介绍了如何在Laravel中保护.env文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将项目移至HOST,但仍可以使用地址mysite.com/.env访问.env,并显示此文件以及所有变量和安全数据. 我的.env文件:

I moved my project to HOST but I can still access .env with address mysite.com/.env and display this file with all variables and secure data. my .env file :

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:xxxxxxx
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=xx
DB_USERNAME=xx
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

我如何保护此文件?这是合乎逻辑的解决方案吗?

How I can protect this file? And this is the logical solution?

注意:(我将所有文件公用文件夹移到根目录中.)

note : (I move all files public folder in root directory.)

推荐答案

在您的根目录中创建.htaccess文件,并放置以下代码.

Create .htaccess file in your Root Directory and put following Code.

#Disable index view
options -Indexes

#hide a Specifuc File

<Files .env>
order allow,deny
Deny from all
</Files>

这篇关于如何在Laravel中保护.env文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆