具体错误如下:
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/ytzc/thinkphp/start.php) is not within the allowed path(s): (/home/wwwroot/ytzc/public_html:/tmp/:/proc/) in /home/wwwroot/ytzc/public_html/index.php on line 20
Warning: require(/home/wwwroot/ytzc/thinkphp/start.php): failed to open stream: Operation not permitted in /home/wwwroot/ytzc/public_html/index.php on line 20
Fatal error: require(): Failed opening required '/home/wwwroot/ytzc/public_html/../thinkphp/start.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/ytzc/public_html/index.php on line 20
(显示错误信息,需打开 php.ini 中 display_errors = On)
错误原因: open_basedir 配置错误。
nginx 配置如下(域名.conf):
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name 域名;
index index.html index.htm index.php;
root 访问目录;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include rewrite/thinkphp.conf;
#open_basedir配置在此文件
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/ytzc_access.log;
}
打开 enable-php.conf 文件:
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
#fastcgi配置
include fastcgi.conf;
}
打开 fastcgi.conf:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
#open_basedir配置
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root:/tmp/:/proc/";
如上找到 open_basedir 目录修改如下:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/:/tmp/:/proc/";
解决这个问题主要是找对位置,否则只会做无用功。
如有侵权请邮件通知