[英]laravel framework : is it safe to move index.php from public folder to the project root?
[英]Laravel - move index.php file in project/public
我将Laravel项目托管在共享主机上,在该主机上我无权修改apache配置以在/public
查找index
文件。
我还尝试过在主机正在寻找index.php
文件的位置将DirectoryIndex index.html
添加到我的.htaccess
文件中。
这是行不通的。
话虽这么说,但我认为只要将index.php
文件从/public
(默认为Laravel在其中)移到托管正在寻找它的root
,就可以解决问题。
话虽这么说,我需要在这个index.php
文件中进行哪些修改才能使Laravel应用程序正常工作?
我的结构是:
public_html/ <-- where my files are served from and where index.php should be
my-project/
public/
index.php <-- where Laravel expects index.php to be to bootstrap the app
好的,我们开始:
假设这是您的文件夹结构:
MyUser/
public_html/
public/
步骤1.在与public_html
相同的级别上创建一个名为laravel
的文件夹(或您喜欢的名称):
MyUser/
laravel/
public_html/
public/
步骤2.将您所有的laravel代码上传到laravel
文件夹。 现在无法通过网络浏览器访问您的代码。
步骤3.接下来,将所有数据从MyUser/Laravel/public
复制到MyUser/public_html
。 现在我们到了某个地方。 警告: 不要忘记也复制.htaccess
文件
步骤4.在您喜欢的编辑器中打开MyUser/public_html/index.php
并进行更改
$app = require __DIR__.'/../bootstrap/app.php';
至:
$app = require __DIR__.'/../laravel/bootstrap/app.php';
并更改:
require __DIR__.'/../bootstrap/autoload.php'
至:
require __DIR__.'/../laravel/bootstrap/autoload.php'
步骤5.现在,由于您的storage
目录位于public_html
之外,因此很可能无法访问,因此将其CHMOD
为777,就可以完成了!
一个小提示:
查看是否可以创建从MyUser/laravel/public
到MyUser/public_html
的symlink
。 您可以跳过第3步和第4步。
希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.