Laravel 5.2 Avoiding public folder and open direct

2019-09-10 21:37发布

The reason why I'm doing that is Laravel has the document root in a subdirectory is so that you don't have to expose your code to the public.

The folder structure in my localhost is

Test
    Test/laravel/
    Test/public_html/

where laravel contains all the folder of root without the public folder and public_html contains the public files.

And I have changed in below lines in public_html/index.php:

require __DIR__.'./../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'./../laravel/bootstrap/app.php';

I have followed the solution for solving the problem but couldn't solve it as I'm using 5.2. If anyone has done this before please provide a valid solution.

Thanks in advance.

1条回答
Luminary・发光体
2楼-- · 2019-09-10 22:12

Laravel already comes with the public directory (which would be easily renamed public_html). However, looking at your code, an issue lies at **./**../laravel/bootstrap/autoload.php'

This would end up with a directory like Test./ instead of Test/. Remove the period before the first slash.

require __DIR__.'/../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
查看更多
登录 后发表回答