1. 程式人生 > 其它 >PHP相關配置

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 [email protected]
    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