PHP相关配置

PHP相关配置

PHP基本配置

1.拷贝配置文件

cd /usr/local/src/php-5.6.30/
cp php.ini-production /usr/local/php/etc/php.ini
[root@antong php-5.6.30]# /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

2.配置php.info

配置php.info调用的是一个程序,不是服务。

[root@antong www.111.com]# cat 123.php    
<?php
phpinfo();
?>

网页效果:

3.修改php.ini文件

vim /usr/local/php/etc/php.ini
date.timezone = Asia/Shanghai  //配置时间格式
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

PHP日志相关配置

禁用phpinfo后日志信息会显示在网页上。

配置php.ini文件

vim /usr/local/php/etc/php.ini
display_errors = off       //不显示错误日志,off为不显示
error_log = /tmp/php_errors.log    //指定错误日志路径
log_errors = 
error_reporting =        //错误报告的级别,根据级别记录错误报告

配置open_basedir

安全选项,一台服务器跑了n个站点,可能出现漏洞会被黑掉,增加了open_basedir可以让站点之间有隔离,不会被黑客渗透入侵。

配置php.ini或配置httpd-vhosts.conf

vim /usr/local/php/etc/php.ini
open_basedir = /usr/local/apache2.4/docs/www.111.com/admin:/tmp //只放开admin,其他网页无法访问。

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache2.4/docs/www.111.com"
    ServerName www.111.com
    ServerAlias 111.com
    php_admin_value open_basedir "/usr/local/apache2.4/docs/www.111.com/admin:/tmp/"
    ErrorLog "logs/www.111.com-error_log"
    CustomLog "logs/www.111.com-access_log" combined
</VirtualHost>
/usr/local/apache2.4/bin/apachectl -t
/usr/local/apache2.4/bin/apachectl graceful
posted @ 2021-08-13 20:31  殇黯瞳  阅读(65)  评论(0编辑  收藏  举报