[英]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.