【问题标题】:Laravel - move index.php file in project/publicLaravel - 在项目/公共中移动 index.php 文件
【发布时间】:2017-10-27 20:53:57
【问题描述】:

我在共享主机上托管我的 Laravel 项目,我无权修改 apache 配置以在 /public 中查找 index 文件。

我还尝试将DirectoryIndex index.html 添加到我的.htaccess 文件中,在主机正在寻找index.php 文件的地方。

这不起作用。

话虽如此,我想我可以解决这个问题,只要我将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

【问题讨论】:

  • 如果您要托管它,那么只需将您的域指向 Laravel 公共文件夹,为什么需要将 index.php 移到公共文件夹之外?

标签: php apache laravel .htaccess laravel-5.1


【解决方案1】:

好的,我们开始吧:

假设这是您的文件夹结构:

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 步。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 2016-01-08
    • 1970-01-01
    • 2021-03-18
    • 2020-07-29
    • 2019-10-10
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多