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

samsoft's avatar

How to hide .env file

Please how can i secure my .env file from been access from the broswer. my .env file display on the broswer if type domain.com/laravel/.env

I'm using godaddy share hosting.

Please help

0 likes
15 replies
coder's avatar

which Laravel version you are using ? and did you try the same thing from you local server ?

samsoft's avatar

I'm using Laravel 5, change the APP_ENV=Production but can still access it when i go to domain/com/laravel/.env

samsoft's avatar

I just check locally... i can't access .env file. but i can access it online when i navigate to domain.com/laravel/.env laravel is a folder where i store the laveral file excluding the public files. I'm using share hosting, all my domain file was deleted 24hours ago, call Godaddy, they ask me to pay $150 for recover my file... please i need to secure my .env file. Thanks

bytefury's avatar

I don't understand. which domain files are you talking about ? & how is that related to .env file

coder's avatar

just delete the .env file from your server and create a new one ,dont give full permission to that and add you configuration details . i hope this will help.

Snapey's avatar

if you install correctly it should be above the root directory and inaccessible.

#1 starter error

1 like
safoorsafdar's avatar

basically it out of the public directory which is not accessable through browser.

pmall's avatar

That is why the vhost root must be the public folder

albro's avatar

You may Add This line in your htaccess RewriteRule ^.env - [F,L,NC]

Snapey's avatar

We need a thumbs-down button

1 like
jlrdw's avatar

Oh my goodness this has only been discussed several hundred times.

I'm actually tired of putting the link in a post at least once a week. To all users, please do a search.

Vilfago's avatar

@jlrdw don't worry, just an old thread coming back... 2 years old

@Snapey I use the spam button, maybe it do the work ?

click's avatar

Maybe laracasts could give some of the users with 1.000.000XP the "veteran" status that allows them to mark answers as "SUPER DEPRECATED SOLUTION" =)

jlrdw's avatar

Sorry I was on phone and it doesn't show how old the thread was my apologies.

Please or to participate in this conversation.