php.ini

最後更新: 2015-06-15

介紹

 

 


; ';' 是注解來

 

; 不用以全寫的 <?php 作為 script 的開始

short_open_tag = On

;

zlib.output_compression = On

 

include_path='.:/usr/share/psa-horde:/usr/share/psa-horde/lib:/usr/share/psa-pear'

 

; 為安全, 停用部份 function

disable_functions =show_source,system,shell_exec,passthru,exec,phpinfo,proc_open ;

register_globals = Off

default_mimetype = "text/html"

 

; 不設定他時常會有 warning

date.timezone = Asia/Hong_Kong

 

; 有關 upload file 的設定

file_uploads = On

upload_max_filesize = 50M

; post size 一定要 > upload size

post_max_size = 60M

; uploaded via a single request

max_file_uploads = 10

 


max_execution_time

 

; 單位: 秒, default: 30

; hardcoded to 0 for the CLI SAPI

max_execution_time = 30

Remark

If this is reached, the script returns a fatal error.

---

To get the currently used time, use "getrusage()"

---

On non Windows systems, the maximum execution time is

not affected by system calls, stream operations and database queries etc.

ie.

sleep, file_get_contents, shell_exec, mysql_query

---

When called, set_time_limit() restarts the timeout counter from zero. zero => no time limit is imposed

i.e.

After 25 sec the script execution a call such as set_time_limit(20),

the script will run for a total of 45 sec)

 


memory_limit = 96M

 


# each script may spend parsing request data(GET, POST).

max_input_time = 60

 


Debug 相關

 

; 每句 print(), echo() 都有 flush(), 用於 Debug

implicit_flush = Off

error_reporting  =  E_ALL & ~E_NOTICE

display_errors = Off

display_startup_errors = Off

log_errors = Off

ignore_repeated_errors = Off

log_errors_max_len = 1024

error_log = /var/log/php.log

 


url_fopen

 

# treatment of URLs (like http:// or ftp://) as files

allow_url_fopen = On

# "include/require" to open URLs

allow_url_include = Off

# seconds

default_socket_timeout = 30

 

 


Module Settings

 

[mail function]

sendmail_path =

 

[MySQL]

mysql.allow_persistent = On

mysql.max_links = -1

mysql.connect_timeout = 60

[Session]

session.save_handler = files

session.save_path = /var/lib/php5

session.use_cookies = 1

; seconds, Default: 24min

session.gc_maxlifetime= 1440

session.name = PHPSESSID

session.auto_start = 0

; until browser is restarted

session.cookie_lifetime = 0

 


PHP5 TimeZone Error

 

php5.3.x 以上才會有此 Error

php.ini 找到

[Date]
;date.timezone = "Asia/Taipei"

或在 php code 內只要輸入

date_default_timezone_set("Asia/Taipei");

 


session.gc_maxlifetime

 

php_value session.gc_maxlifetime "3600"

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
; http://php.net/session.cookie-lifetime

session.cookie_lifetime = 0

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
; http://php.net/session.gc-maxlifetime
; 24 min

session.gc_maxlifetime = 1440

 


user_ini

 

These files are processed only by the CGI/FastCGI SAPI

; sets the name of the file PHP looks for in each directory
; To disable this feature set this option to empty value
user_ini.filename = .user.ini

; controls how often user INI files are re-read (Unit: Second)
user_ini.cache_ttl = 300

 


php-cgi 的 php.ini

 

建立一個 php 測試

<?php phpinfo(); ?>

OR

php-cgi -i | grep ini

Loaded Configuration File: /etc/php5/cgi/php.ini

Scan this dir for additional .ini files: /etc/php5/cgi/conf.d

Additional .ini files parsed

/etc/php5/cgi/conf.d/*.ini

mod_php 修改 ini 的位置

cp /etc/php5/cgi/php.ini /home/vhosts/xxx/ini

<VirtualHost 1.2.3.4:80>
[...]
# mod_php
PHPINIDir /home/vhosts/xxx/ini
[...]
</VirtualHost>

 

php-cgi 的 php.ini

php-cgi -v

PHP 5.3.10-1ubuntu3.15 with Suhosin-Patch (cgi-fcgi) (built: Oct 29 2014 12:12:21)

# PHP information and configuration

php-cgi -i | grep ini

<tr><td class="e">Configuration File (php.ini) Path </td><td class="v">/etc/php5/cgi </td></tr>
<tr><td class="e">Loaded Configuration File </td><td class="v">/etc/php5/cgi/php.ini </td></tr>
<tr><td class="e">Scan this dir for additional .ini files </td><td class="v">/etc/php5/cgi/conf.d </td></tr>
.................

php-cgi

-f             # parse and execute files
-c path|file   # Look for php.ini file in the directory path

# fcgid
<IfModule mod_fcgid.c>
    AddHandler fcgid-script .php
    FcgidWrapper "/usr/bin/php-cgi -c /home/vhosts/xxx/ini" .php
    RewriteEngine On
    RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
    <Directory /usr/share/phpMyAdmin/>
            Options +ExecCGI
            Deny from All
            Allow from 127.0.0.1
            Allow from 115.160.172.18
    </Directory>
</IfModule>

ps aux | grep php-cgi

/usr/bin/php-cgi -c /home/vhosts/bnw.hk/ini

 


Apache 爆 error log

 

log

[Fri Nov 04 09:40:03 2016] [error] [client ::1] PHP Notice:  Undefined variable: ...

修改 php.ini 設定檔

error_reporting integer

# E_ALL: All errors and warnings (doesn't include E_STRICT), not included in E_ALL until PHP 5.4.0

# E_STRICT: PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT

OR

error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR