TP5.0.20 – TP5更改網站目錄為/public 後運行出錯解決

  • 2019 年 12 月 15 日
  • 筆記

今天在部署TP5的時候,把網站根目錄指向到public目錄下,運行後產生以下錯誤

Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/xx/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/xx/public/:/tmp/:/proc/) in /www/wwwroot/xx/public/index.php on line 18    Warning: require(/www/wwwroot/xx/thinkphp/start.php): failed to open stream: Operation not permitted in /www/wwwroot/xx/public/index.php on line 18    Fatal error: require(): Failed opening required '/www/wwwroot/xx/public/../thinkphp/start.php' (include_path='.:/www/server/php/70/lib/php') in /www/wwwroot/xx/public/index.php on line 18

就是require文件的時候出錯了,並且帶上了文件的路徑,一開始以為是路徑出錯的,於是在index.php中嘗試修改 引入的文件路徑,發現index.php並沒有問題。

百度發現:open_basedir 的問題  需要在php.ini中修改open_basedir你的項目路徑,或者在nginx中也可以定義。

但是我的兩個配置文件中都沒有該配置參數,於是繼續找問題。後來想到伺服器使用了寶塔面板來管理的,指定子目錄也是在寶塔面板中進行。

於是到寶塔面板的頁面,發現有一個   防跨站攻擊(open_basedir)    的選項 把該選項關閉即可。

原因如下:open_basedir 將PHP所能打開的文件限制在指定的目錄樹中,包括文件本身。當程式要使用例如fopen()或file_get_contents()打開一個文件時,這個文件的位置將會被檢查。當文件在指定的目錄樹之外,程式將拒絕打開。

本指令不受安全模式打開或關閉的影響。

Tags: