最後更新: 2015-06-15




; ';' 是注解來


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

short_open_tag = On


zlib.output_compression = On




; 為安全, 停用部份 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




; 單位: 秒, default: 30

; hardcoded to 0 for the CLI SAPI

max_execution_time = 30


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.


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


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




# 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.allow_persistent = On

mysql.max_links = -1

mysql.connect_timeout = 60


session.save_handler = files

session.save_path = /var/lib/php5

session.use_cookies = 1

; seconds, Default: 24min

session.gc_maxlifetime= 1440 = PHPSESSID

session.auto_start = 0

; until browser is restarted

session.cookie_lifetime = 0


PHP5 TimeZone Error


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

php.ini 找到

;date.timezone = "Asia/Taipei"

或在 php code 內只要輸入





php_value session.gc_maxlifetime "3600"

; Lifetime in seconds of cookie or, if 0, until browser is restarted.

session.cookie_lifetime = 0

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
; 24 min

session.gc_maxlifetime = 1440




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(); ?>


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


mod_php 修改 ini 的位置

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

# mod_php
PHPINIDir /home/vhosts/xxx/ini


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>


-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
            Allow from

ps aux | grep php-cgi

/usr/bin/php-cgi -c /home/vhosts/


Apache 爆 error 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