[root@zlinux ~]# /usr/local/php/bin/php -i | grep -i "Loaded Configuration file"
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
Loaded Configuration File => /usr/local/php/etc/php.ini
第一行是warning警告信息,可以忽略,如想想取消则需要编辑php.ini,找到date.timezone设置为:
[root@zlinux ~]# vim /usr/local/php/etc/php.ini //取消前面;号
date.timezone = Asia/Shanghai
[root@zlinux ~]# curl -A "www" -x 192.168.204.128:80 linuxtest.com/indextest.php -I //故意去掉phpinfo函数的括号
HTTP/1.0 500 Internal Server Error
Date: Wed, 07 Mar 2018 07:51:56 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
X-Powered-By: PHP/5.6.30
Connection: close
Content-Type: text/html; charset=UTF-8
出现了500状态码,此时就可以查看PHP错误日志了:
[root@zlinux php]# cat php_errors.log
[07-Mar-2018 16:00:49 Asia/Shanghai] PHP Parse error: syntax error, unexpected '?>' in /data/wwwroot/123test/indextest.php on line 3 四、配置open_basedir
open_basedir可将用户访问文件的活动范围限制在指定的区域,通常是其家目录的路径,也
可用符号"."来代表当前目录。注意用open_basedir指定的限制实际上是前缀,而不是目录名。
[root@zlinux php]# vim /usr/local/php/etc/php.ini
; open_basedir, if set, limits all file operations to the defined directory
; and below. This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file.
; http://php.net/open-basedir
open_basedir = /usr/local/wwwroot/123test:/tmp //多个目录用:隔开,这个说明PHP限制在这两个目录活动
测试是否只能在这俩目录下活动:
[root@zlinux php]# curl -A "www" -x 192.168.204.128:80 ztest.com/openbasedir.php -I
HTTP/1.0 500 Internal Server Error
Date: Wed, 07 Mar 2018 08:14:04 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
X-Powered-By: PHP/5.6.30
Connection: close
Content-Type: text/html; charset=UTF-8
//状态码500,查看日志
[root@zlinux php]# cat php_errors.log
[07-Mar-2018 16:00:49 Asia/Shanghai] PHP Parse error: syntax error, unexpected '?>' in /data/wwwroot/123test/indextest.php on line 3
[07-Mar-2018 16:13:57 Asia/Shanghai] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/wwwroot/abctest/openbasedir.php) is not within the allowed path(s): (/usr/local/wwwroot/123test:/tmp) in Unknown on line 0
[07-Mar-2018 16:13:57 Asia/Shanghai] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[07-Mar-2018 16:13:57 Asia/Shanghai] PHP Fatal error: Unknown: Failed opening required '/data/wwwroot/abctest/openbasedir.php' (include_path='.:/usr/local/php/lib/php') in Unknown on line 0
[07-Mar-2018 16:14:04 Asia/Shanghai] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/wwwroot/abctest/openbasedir.php) is not within the allowed path(s): (/usr/local/wwwroot/123test:/tmp) in Unknown on line 0
[07-Mar-2018 16:14:04 Asia/Shanghai] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[07-Mar-2018 16:14:04 Asia/Shanghai] PHP Fatal error: Unknown: Failed opening required '/data/wwwroot/abctest/openbasedir.php' (include_path='.:/usr/local/php/lib/php') in Unknown on line 0
//通过日志可以看出,要访问的页面不在规定目录下。
也可以给单个虚拟主机设置open_basedir:
[root@zlinux ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf //添加如下内容
php_admin_value open_basedir "/data/wwwroot/123test;:/tmp"