簡體   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