今天在部署一个ThinkPHP5开发的网站时,把网站根目录指向到public目录下,结果运行后产生以下错误
Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/xxx/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/xxx/public/:/tmp/:/proc/) in /www/wwwroot/xxx/public/index.php on line 18
Warning: require(/www/wwwroot/xxx/thinkphp/start.php): failed to open stream: Operation not permitted in /www/wwwroot/xxx/public/index.php on line 18
Fatal error: require(): Failed opening required '/www/wwwroot/xxx/public/../thinkphp/start.php' (include_path='.:/www/server/php/70/lib/php') in /www/wwwroot/xxx/public/index.php on line 18
到宝塔面板的网站配置页面,发现有一个“防跨站攻击(open_basedir) 的选项”把该选项关闭即可。
原因如下:open_basedir 将PHP所能打开的文件限制在指定的目录树中,包括文件本身。当程序要使用例如fopen()或file_get_contents()打开一个文件时,这个文件的位置将会被检查。当文件在指定的目录树之外,程序将拒绝打开。
如果首页能打开了,内页打不开,设置一下伪静态为thinkphp试试