Laravel 5.2 Avoiding public folder and open directly from root in localhost

北城余情 提交于 2019-12-12 05:38:29

问题


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:


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';


来源:https://stackoverflow.com/questions/37958149/laravel-5-2-avoiding-public-folder-and-open-directly-from-root-in-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!