Laravel .env Exposed

Mohit Mehta
2 min readDec 16, 2020

When it comes to host a Laravel project on shared hosting, many of the developers finds a difficulty. So they just apply any random solutions from different websites to make their project working without even knowing the consequence of that. Let me give one example.

One of the easiest way of Laravel hosting is move all files of public folder to root and make some changes in index.php

Once you go with above solution, you are opening doors for the hackers and attackers. Because Laravel’s base directory has many important files like .env, .htaccess etc and your web-server is also pointing to Laravel’s base directory. So these all important files can directly be accessed by URL. For example, .env file can be accessed via www.example.com/.env and it results,

.env exposed

In conclusion, never ever host Laravel like this. If you have shared hosting and you have less knowledge about server related stuffs then ask you hosting provider to change documentRoot to Laravel’s public folder.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Mohit Mehta
Mohit Mehta

Written by Mohit Mehta

Full stack enthusiastic developer

Responses (2)

Write a response

Ive literally just wrote a post about Laravel in shared hosting environment. More from an SEO perspective: https://leemason.co.uk/laravel-on-shared-hosting/
The solution provided there doesn't have this risk. But i 10000% agree shared hosting of Laravel should be where possible.

2

Basically most of the shared hosting setups that use CPanel Control Panel and other panels simply allow to upload files/folders outside public_html (i.e. webroot), and this way, they can upload content of public into public_html and all files &…