Laravel out of servers root directory

Viewed 596

I found the following part in Laravel's documentation.

"Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files present within your application."

Does it mean it should be always directly in root directory, not in subdirectories or the other way?

What if my server provider gives me root directory / and tells me to put my files into /www ?

Does it make it vulnerable then?

3 Answers

I disagree with the above answer of @Jean-Roch B. and agree with the comment of @Tpojka.

If the root of the "web directory" on your server is /var/www you should put Laravel in that folder

No. The root directory (DocumentRoot as defined by https://httpd.apache.org/docs/2.4/mod/core.html#documentroot) is aimed to allow the HTTP server to provide the client the files recursively under. Meaning that siblings and recursively parents directories can't be provided to the client.

What does it means? That if you put Laravel recursively under the root directory, you will have a security issue. For example, the config and environment files, your controllers, your migration files etc., would be provided to the client if this latter asks for them.

By saying the following:

Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files present within your application.

, Laravel docs are saying to NOT put the Laravel directory recursively under the document root. YOU ABSOLUTELY MUST PUT THE LARAVEL DIRECTORY RECURSIVELY ABOVE THE DOCUMENT ROOT.

The document root, with a Laravel site, must ONLY point to the directory app/public of the Laravel directory.

I will quote @Tpojka (see his comment to the OP's question), who is absolutely right:

Nothing outside public directory shouldn't be available to external access. Only public directory should be accessible by externals. Everything else is lot of work on securing application.

Also, quoting again @Jean-Roche B.:

Obviously it's not a good idea to put Laravel in /var/otherdirectory or /otherdirectory

, if like he was saying /var contains /var/www, I thin rather that Laravel could actually be put in /var, delete www, and make the root directory be the app/public directory (this is an example).

To end: the DocumentRoot can normally be configured in your Web Host configuration admin panel.

Laravel is not very clear on this.

But what I understand is:

If the root of the "web directory" on your server is /var/www you should put Laravel in that folder and not in /var/www/otherdirectory or /var/otherdirectory or /otherdirectory

Obviously it's not a good idea to put Laravel in /var/otherdirectory or /otherdirectory, but why they say only at the root of the "web directory" and not in /var/www/otherdirectory ? I think nobodies knows and Laravel can't explain it really.

  • The root directory on a linux server is /
  • The root of the "web directory"directory on a linux server can be whatever is in your web server configuration or whatever your provider gave you (if you can't manage the web server configuration), but most of the time it's in /var/www, /var/www/html or /var/www/domain.com

Also Laravel members seem to be saying that you can't use Laravel in a subdirectory website like https://example.com/website because (Laravel say) they don't support it and (Laravel say) it's not recommended, even if this website is served out of the root of the "web directory" which is /var/www in most cases. (But why???)

See the discussion here: Discussion 34388

So I am assuming you are using a shared hosting server:

the way websites are hosted is using a web server (apache, nginx, ...etc) (if you are using godaddy or namecheap hosting they will have a webserver installed inside ) in these web servers you set a document root as in where should the server direct the requests.

Knowing this if your server says put the files in /www then its most likely that /www is the document root and its where you should put the files

Note: whatever server you use i would be 99.9% sure that you should not put the website files or the actual root of the server aka /

Related