LAMP环境搭建与配置(3)

PHP配置

查看PHP配置文件的位置

#  /usr/local/php/bin/php   -i  |grep  -i  "loaded configuration file"

 把一些存在安全风险的函数禁掉

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

重启httpd服务使其生效

配置error_log

设置php错误日志

# vi  /usr/local/php/etc/php.ini

 修改以下内容

扫描二维码关注公众号,回复: 12243386 查看本文章

 

 

 

log_errors 如果想让PHP记录错误日志,需要设置成on

error_log 设定错误日志路径

error_reporting 设定错误日志的级别,E_ALL为所有类型的日志,&表示并且,~表示排除,意思是在E_ALL的基础上排除掉notice相关的日志

# mkdir  /var/log/php  需要保证PHP的错误日志所在目录存在

# chmod  777  /var/log/php

# /usr/local/apache2.4/bin/apachectl  graceful

测试

在其中写入错误内容

 

访问

# curl   -A"123"  -I  -x127.0.0.1:80  www.0209.com/test.php

出现状态码500,说明访问的页面是存在错误的

查看PHP的错误日志判定错误原因

# cat  /var/log/php/php_error.log

配置open_basedir

配置文件

# vi  /usr/local/php/etc/php.ini

搜索open_basedir

重新加载配置

# /usr/local/apache2.4/bin/apachectl  graceful

测试

# cp  /usr/local/apache2.4/htdocs/1.php  /data/wwwroot/gmd.com/

# curl  -x127.0.0.1:80  -I  gmd.com/1.php

不能访问

给单个虚拟机设置open_basedir

# vi  /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot  "/data/wwwroot/www.0209.com"
    ServerName  www.0209.com
    ServerAlias  0209.com
    CustomLog  "|/usr/local/apache2.4/bin/rotatelogs  -l  logs/0209.com-access_%Y%m%d.log  86400"
    php_admin_value  open_basedir  "/data/wwwroot/www.0209.com/:/tmp/"
</VirtualHost>

重新加载配置

# /usr/local/apache2.4/bin/apachectl -t

# /usr/local/apache2.4/bin/apachectl  graceful

PHP动态扩展模块安装

查看加载了哪些模块

# /usr/local/php/bin/php  -m

安装redis扩展模块

# cd  /usr/local/src/

# wget  http://pecl.php.net/get/redis-2.2.5.tgz

# tar  -zxvf  redis-2.2.5.tgz

# cd  redis-2.2.5

# yum  install  -y  autoconf

# /usr/local/php/bin/phpize    生成configure文件

# ./configure  --with-php-config=/usr/local/php/bin/php-config

# make

# make  install

# /usr/local/php/bin/php  -i  |grep  extension_dir

# ls  /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

# vi  /usr/local/php/etc/php.ini

最后加

extension=redis.so

查看是否加载模块

# /usr/local/php/bin/php  -m  |grep  redis

# cd  /usr/local/apache2.4/htdocs/

浏览器加载模块

# cd  /usr/local/apache2.4/htdocs/

# vi  index.php
<?php
        phpinfo();
?>

重新加载

# /usr/local/apache2.4/bin/apachectl  -t

# /usr/local/apache2.4/bin/apachectl  graceful

浏览器搜索192.168.89.128/index.php

猜你喜欢

转载自blog.csdn.net/qq_45533926/article/details/111991479