Linux9.12 PHP配置

php配置文件

查看PHP配置文件位置

1. 通过PHP命令

#用这个命令很有可能找不到或者不对
[root@chy002 abc.com]# /usr/local/php/bin/php -i| grep -i "configuration file"
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => (none)

2. 通过浏览器访问phpinfo()函数

      上面两种情况通过Loaded Configuration Path看到没有加载配置文件,那么从源码包里复制配置文件到Configuration File Path文件夹内。然后刷新一下apache就发现有了

[root@chy002 etc]# cp /usr/local/src/php-5.6.30/php.ini-development  /usr/local/php/etc/php.ini

  

  限定disable_functions安全函数,甚至可以禁phpinfo

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后,发现浏览器变为:

  date.timezone 时区

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asiz/Chongqing

  

  日志相关选项,

  error_log错误日志记录,

  log_errors定义开启报警,

  display_errors在浏览器上显示,

  error_reporting定义报警日志级别

#开启错误日志,指定错误日志位置/tmp/,把phpinfo函数放到disable_functions,通过浏览器访问,错误日志如下
[root@chy002 etc]# cat /tmp/php_errors.log 
[07-Mar-2018 20:43:47 UTC] PHP Warning:  phpinfo() has been disabled for security reasons in /data/wwwroot/abc.com/index.php on line 2
... ...

可以发现该文件属主和属组为daemon,我们可以提前创建该文件并修改权限,放置权限不够,导致httpd进程写不进去
[root@chy002 etc]# ls -l /tmp/php_errors.log 
-rw-r--r-- 1 daemon daemon 405 3月   8 04:43 /tmp/php_errors.log

  open_basedir作用是把执行php的用户限定在指定的路径下,这样通过权限缩小的方式达到安全的目的,作为一个网站,我们只需要让php用户访问到网站的代码即可,没有必要访问其他目录。

; 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 =

  从php.ini现在的话,会让所有的虚拟机都只能访问该目录。也可以从httd_vhost去修改某几个虚拟主机。

php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"

phpd动态扩展模块安装

   查看php安装的模块

[root@chy002 ~]# /usr/local/php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
... ...

  下面安装一个redis的模块

[root@chy002 ~]# cd /usr/local/src/

#下载redis模块
[root@chy002 src]# wget wget https://codeload.github.com/phpredis/phpredis/zip/develop

[root@chy002 src]# mv develop phpredis-develop.zip
[root@chy002 src]# unzip phpredis-develop.zip 


[root@chy002 src]# cd phpredis-develop/

//生成configure文件
[root@chy002 phpredis-develop]# /usr/local/php/bin/phpize

//进行源码安装
[root@chy002 phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

/查看扩展模块存放目录,我们可以在php.ini中去自定义该路径 
/usr/local/php/bin/php -i |grep extension_dir /
//查看文件夹是否生成redis.so扩展模块
[root@chy002 phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so  redis.so

//查看httpd是否加载redis模块
[root@chy002 phpredis-develop]# /usr/local/php/bin/php -m |grep redis

//编辑httpd配置文件,使httpd加载扩展模块
 vim /usr/local/php/etc/php.ini  //增加一行配置(可以放到文件最后一行)
extension = redis.so  

  

  PHP源码包里ext目录有许多模块文件,可以直接去zip文件内去执行编译。

  

 

posted @ 2018-03-07 19:39  chyuanliu  阅读(192)  评论(0编辑  收藏  举报