php相关配置(总结)
php路径没有加载图1 :
图二禁用php.info的结果
[root@chy ~]# /usr/local/php/bin/php -i
(查看php的路径)
[root@chy 111.com]# vim index.php
<?php
phpinfo ();
(在indix.php里面增加phpinfo)
在网页中可以查看到php的路径,但是有加载(如截图1)
那如果没有加载时就需要在源码包中cp一个了,拷贝方式如下:[root@chy 111.com]# cd /usr/local/src/php-5.6.30/ (进入到源码包中)
[root@chy php-5.6.30]# cp php.ini-development /usr/local/php/etc/php.ini (cp到/etc下)
[root@chy php-5.6.30]# /usr/local/apache2.4/bin/apachectl graceful
(这时还需要刷新配置文件)
[root@chy php-5.6.30]# vim /usr/local/php/etc/php.ini
(在php的配置文件里面做一些操作)
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
(禁用函数,一般也是需要把phpinfo需要禁用掉,因为如果不禁用,php的一些信息就会在网页中显示出来)
[root@chy php-5.6.30]# /usr/local/apache2.4/bin/apachectl graceful
(加载一下配置文件)
(图二是网页访问php.info时被拒绝的结果)
[root@chy php-5.6.30]# vim /usr/local/php/etc/php.ini
date.timezone =Asia/Chongqing
(如果不定义这个会出现报错)
; http://php.net/display-errors
display_errors = Of
(这个显示错误信息也是需要关闭的,如果不关闭报错的信息会显示在网页的页面上)
error_log = /tmp/php_errors.log
(定义错误日志的路径)
error_reporting = E_ALL (记录日志的权限,生产环境用的是 E_ALL & ~E_NOTICE )
[root@chy php-5.6.30]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@chy php-5.6.30]# /usr/local/apache2.4/bin/apachectl graceful
(检查配置,并加载一下配置)
[root@chy php-5.6.30]# curl -A "a" -x127.0.0.1:80 http://www.111.com/index.php
(用curl检测时发现没有任何的显示,这里加-A是因为之前做了user_agent的配置)
[root@chy php-5.6.30]# ls -l /tmp/php_errors.log
-rw-r--r-- 1 daemon daemon 438 8月 4 08:09 /tmp/php_errors.log
[root@chy php-5.6.30]# ps aux |grep httpd
root 2448 0.0 0.7 245632 11668 ? Ss 05:05 0:02 /usr/local/apache2.4/bin/httpd -k start
daemon 5108 0.0 0.5 534596 9132 ? Sl 08:11 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 5109 0.0 0.5 534596 9132 ? Sl 08:11 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 5110 0.0 0.5 534596 9132 ? Sl 08:11 0:00 /usr/local/apache2.4/bin/httpd -k start
root 5199 0.0 0.0 112664 976 pts/0 S+ 08:13 0:00 grep --color=auto httpd
(这里需要注意的是如果发现更改了php配置文件后,也设置了错误日志的路径与权限还是没有记录错误日志,就需要看看错误日志的目录有没有写权限,这个权限是apache的属主daemon)
错误日志的小案例
[root@chy php-5.6.30]# vim /data/wwwroot/111.com/2.php (写一个2.php)
[root@chy php-5.6.30]# curl -A "c" -x127.0.0.1:80 http://www.111.com/2.php -I
HTTP/1.0 500 Internal Server Error
Date: Fri, 04 Aug 2017 00:22:37 GMT
Server: Apache/2.4.27 (Unix) PHP/5.6.30
X-Powered-By: PHP/5.6.30
Connection: close
Content-Type: text/html; charset=UTF-8
(状态码为500,为500的原因是2.php的语法故意写错了)
[root@chy php-5.6.30]# !cat
cat /tmp/php_errors.log
[04-Aug-2017 08:07:05 Asia/chongqing] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/111.com/index.php on line 2
[04-Aug-2017 08:07:09 Asia/chongqing] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/111.com/index.php on line 2
[04-Aug-2017 08:09:56 Asia/chongqing] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/111.com/index.php on line 2
[04-Aug-2017 08:22:37 Asia/chongqing] PHP Parse error: syntax error, unexpected end of file in /data/wwwroot/111.com/2.php on line 4
(查看错误日志)
网站隔离(A,B网站互不影响,当一个网站被黑了,另一个网站没有影响)open_basedir
[root@chy php-5.6.30]# vim /usr/local/php/etc/php.ini
open_basedir =/data/wwwroot/111.com/tmp/
(在php.ini下定义的是整个的网站并达不到需要的效果,如果需要实现每个网站都隔离需要在apache的虚拟配置文件里进行配置)
[root@chy php-5.6.30]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName www.111.com
ServerAlias www.exaple.com
#<Directory /data/wwwroot/111.com>
#<filesMatch 123.php>
#AllowOverride AuthConfig
#AuthName "111.com user auth"
#AuthType Basic
#AuthUserFile /data/.htpasswd
#require valid-user
#</FilesMatch>
#</Directory>
php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"
(针对不同的虚拟主机设置open_basedir,php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"主要配置)