分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

87.PHP配置

发布时间:2023-09-06 01:45责任编辑:傅花花关键词:PHP配置
查看PHP配置文件所在位置
虽然PHP是以httpd一个模块的形式存在的,但是PHP本身也有自己的配置文件。查看PHP配置文件所在位置的命令为:[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 0Loaded 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再次执行就不会提示警告信息了。然后访问一个包含phpinfo函数的页面,会显示这样:

二、PHP的disable_functions

由于phpinfo会显示出服务器内LAMP架构内的很多软件的配置文件等重要文件的信息,所以在生产环境下最好禁掉,防止被黑客获取到系统内部php信息,造成损失。测试环境可以不禁。[root@zlinux ~]# vim /usr/local/php/etc/php.ini ??????//搜索disable_functions,编辑成如下内容disable_functions = eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo[root@zlinux ~]# /usr/local/apache2/bin/apachectl graceful ??????//更改要重新加载下apache服务

三、配置error_log

PHP日志非常重要,它是排查问题的重要手段。步骤如下:[root@zlinux ~]# vim /usr/local/php/etc/php.inilog_errors = On ???????//搜索log_errorserror_log = /var/log/php/ php_errors.log ?????//搜索log_error,改成这个,存放日志的路径error_reporting = E_ALL & ~E_NOTICE ????//搜索error_reporting改成这个display_errors = Off ????????????????????????????????????//改为Off[root@zlinux ~]# /usr/local/apache2/bin/apachectl gracefuldisplay_errors=On/Off :设定是否显示错误原因,需要注意的是,此处设置为off(防止用户看到)后必须设置错误日志,设定保存路径,和错误日志级别,否则将无法查找错误原因 。log_errors=On/Off 开启/关闭错误日志“error_log=/tmp/” 设定错误日志的保存路径。如果定义好路径后无法生产日志,此时需要检查日志文件所在目录是否有写(w)权限“errorreporting =” 设定错误日志级别,级别有:E ALL 、~E NOTICE 、~E STRICT 、~EDEPRECATED(可以自由组合)。生产环境使用:E ALL & ~E_ NOTICE就可以。设置完php.ini之后,需要一些额外操作:[root@zlinux ~]# mkdir /var/log/php[root@zlinux ~]# chmod 777 /var/log/php/ ????????????????????//保证PHP错误日志所在目录存在,并且权限可读写[root@zlinux ~]# /usr/local/apache2/bin/apachectl graceful测试效果:[root@zlinux ~]# curl -A "www" -x 192.168.204.128:80 linuxtest.com/indextest.php -I ????//故意去掉phpinfo函数的括号HTTP/1.0 500 Internal Server ErrorDate: Wed, 07 Mar 2018 07:51:56 GMTServer: Apache/2.4.29 (Unix) PHP/5.6.30X-Powered-By: PHP/5.6.30Connection: closeContent-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-basediropen_basedir = /usr/local/wwwroot/123test:/tmp ????//多个目录用:隔开,这个说明PHP限制在这两个目录活动测试是否只能在这俩目录下活动:[root@zlinux php]# curl -A "www" -x 192.168.204.128:80 ztest.com/openbasedir.php -IHTTP/1.0 500 Internal Server ErrorDate: Wed, 07 Mar 2018 08:14:04 GMTServer: Apache/2.4.29 (Unix) PHP/5.6.30X-Powered-By: PHP/5.6.30Connection: closeContent-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:

87.PHP配置

原文地址:http://blog.51cto.com/sdwaqw/2085288

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved