繁体   English   中英

Laravel-在项目/公共目录中移动index.php文件

[英]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/publicMyUser/public_htmlsymlink 您可以跳过第3步和第4步。

希望这会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM