第四章. 組態設定

目錄
php3.ini 檔案
Apache模組 (Module)
CGI
虛擬主機 (Virtual hosts)
安全 (Security)

php3.ini 檔案

PHP Parser啟動時會去讀php3.ini. Server module 的PHP則在伺服器啟動時就讀入該檔. CGI型態的PHP則在每次被呼叫時讀取該檔.

以下所列之 directive 與 Apache httpd.conf 的 directive都有對應的關係,只需在以下directive names前加上php3_ 即可.

您可使用phpinfo() 的輸出結果得知大部份的PHP設定狀況.

一般設定(General Configuration Directives)

auto_append_file string

指定一個在會被自動加入到檔尾並執行的檔案,就像用 include() function一樣,string只是檔名,所以要有 include_path指定該檔所在位置.

一個特殊值none取消auto-appending功能.

註:如果程式本身是以 exit()結束的話則 auto-append 將 不會起作用.

cgi_ext string

display_errors boolean

設定是否要讓錯誤訊息以HTML格式輸出到畫面上.

doc_root string

PHP的 root directory),只有在string有值時才有效. 如果PHP是被設定成safe mode, 在這目錄以外的PHP檔將不允許被執行

engine boolean

這對Apache module的PHP很有用,您可以在不同的目錄或虛擬主機開啟或關閉 PHP的執行權限,只要把php3_engine off 加到httpd.conf的正確位置就行了.

error_log string

記錄錯誤訊息的log檔名,如果是syslog, 則會記錄在系統的log檔案中.UNIX上是指syslog(3),在Windows NT則是指 事件記錄(event log).這功能在Windows 95上是無效的.

error_reporting integer

設定錯誤報告的等級,由一組一bit的整數參數來區分您所要設的水平標準, 您可以把這些整數加起來組合使用.

Table 4-1. 錯誤等級報告 Error Reporting Levels

bit value enabled reporting
1 正常錯誤(normal errors)
2 正常警告(normal warnings)
4 直譯錯誤(parser errors)
8 非致命性格式警告(non-critical style-related warnings)
預設值為7,即以上的1+2+4

open_basedir string

限制PHP在指定目錄的開檔的權限.

如果一個script要開啟一個檔案,比如說 fopen 或 gzopen, 則檔案的位置將先會被驗證是否合法,如果檔在是在指定目錄以外則動作不被允許 就算使用連結(symbolic link)也無法避開這個限制,因為所有的連結檔將會被驗證其實際路徑.

句點(.)這個特殊值指示只能開啟PHP程式 所在目錄中之檔案

預設值為可以開啟所有檔案

gpc_order string

設定GET/POST/COOKIE變數傳送之順序. 初始設定為"GPC".如果設成"GP",則PHP將完全忽略cookies而把所有使用 同樣名稱之傳輸變數(假設一個name有用POST及GET同時被送出) 以GET方式傳送.

include_path string

指定require(), include()fopen_with_path()用到時要找出檔案的一串路徑或目錄名稱. 格式就像系統的PATH環境變數: 在UNIX中以冒號(:)隔開這串目錄,Windows上則以分號來區隔(;).

Example 4-1. UNIX include_path

include_path=.:/home/httpd/php-lib

Example 4-2. Windows include_path

include_path=".;c:\www\phplib"
預設的值是句號(.),即只有工作目錄

isapi_ext string

log_errors boolean

是否設定把錯誤記錄在伺服器的error log,所以這可以由伺服器設定檔中指定.

magic_quotes_gpc boolean

設定GPC (Get/Post/Cookie)之magic_quotes狀態, 如果 magic_quotes 是 on 的話, 所有的單引號 ' (single-quote), 雙引號 " (double quote), 反斜線 \ (backslash) 和空字元NUL 將會自動加上反斜線(\, backslash). 假如magic_quotes_sybase也被設為on, 則單引號(',single-quote)將會自動加在 單引號前(而不是反斜線).

magic_quotes_runtime boolean

如果magic_quotes_runtime被啟動,多數的 functions傳回的值,包含來自資料庫或文字檔將會自動加上反斜線(\,backslash). 如果magic_quotes_sybase也為on,則單引號將會 自動被複製.

magic_quotes_sybase boolean

如果magic_quotes_sybase是on, 而magic_quotes_gpc magic_quotes_runtime也是on的話,則單引號將會自動複製,而不是在單引號 之前加上一個反斜線.

max_execution_time integer

最長的執行時間(以秒為單位),此設定可以避免一些爛程式把伺服器操到無法正常運作.

memory_limit integer

最大的記憶體使用空間(單位為位元組bytes),避免爛程式把伺服器的記憶體吃光光.

nsapi_ext string

short_open_tag boolean

允許PHP使用<? ?>. 如果您要和XML一起使用則必須關閉此功能,使用PHP時要以 <?php ?>括起來.

sql.safe_mode boolean

track_errors boolean

如果被enable的話,則在global variable ($php_errormsg)中會存放最近一次的錯誤訊息.

track_vars boolean

如果有設定則 GET, POST 和 cookie 等將各別被存入global associative arrays 中的 $HTTP_GET_VARS, $HTTP_POST_VARS$HTTP_COOKIE_VARS.

upload_tmp_dir string

上載檔案時的暫存目錄,一定要是PHP的執行使用者(如果是Apache modeul PHP則此為 跑Apache的user)有可寫入的權限之目錄

user_dir string

系統使用者的根目錄中允許執行PHP的目錄,如public_html.

warn_plus_overloading boolean

如果啟動,則PHP會輸出警訊,當加號( +)被用在字串時. 這使得一些需要重寫的script更容易被找到, 並用回正常的字串連接功能 (.).

郵件設定(Mail Configuration Directives)

SMTP string

DNS name or IP address of the SMTP server PHP under Windows should use for mail sent with the mail() function.

sendmail_from string

Which "From:" mail address should be used in mail sent from PHP under Windows.

sendmail_path string

Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, Qmail users can normally set it to /var/qmail/bin/sendmail.

安全模式設定(Safe Mode Configuration Directives)

safe_mode boolean

Whether to enable PHP's safe mode. Read the Security chapter for more more information.

safe_mode_exec_dir string

If PHP is used in safe mode, system() and the other functions executing system programs refuse to start programs that are not in this directory.

除錯設定(Debugger Configuration Directives)

debugger.host string

DNS name or IP address of host used by the debugger.

debugger.port string

Port number used by the debugger.

debugger.enabled boolean

Whether the debugger is enabled.

Extension Loading Directives

enable_dl boolean

This directive is really only useful in the Apache module version of PHP. You can turn dynamic loading of PHP extensions with dl() on and off per virtual server or per directory.

The main reason for turning dynamic loading off is security. With dynamic loading, it's possible to ignore all the safe_mode and open_basedir restrictions.

The default is to allow dynamic loading, except when using safe-mode. In safe-mode, it's always imposible to use dl().

extension_dir string

In what directory PHP should look for dynamically loadable extensions.

extension string

Which dynamically loadable extensions to load when PHP starts up.

MySQL Configuration Directives

mysql.allow_persistent boolean

Whether to allow persistent MySQL connections.

mysql.max_persistent integer

The maximum number of persistent MySQL connections per process.

mysql.max_links integer

The maximum number of MySQL connections per process, including persistent connections.

mSQL Configuration Directives

msql.allow_persistent boolean

Whether to allow persistent mSQL connections.

msql.max_persistent integer

The maximum number of persistent mSQL connections per process.

msql.max_links integer

The maximum number of mSQL connections per process, including persistent connections.

Postgres Configuration Directives

pgsql.allow_persistent boolean

Whether to allow persistent Postgres connections.

pgsql.max_persistent integer

The maximum number of persistent Postgres connections per process.

pgsql.max_links integer

The maximum number of Postgres connections per process, including persistent connections.

Sybase Configuration Directives

sybase.allow_persistent boolean

Whether to allow persistent Sybase connections.

sybase.max_persistent integer

The maximum number of persistent Sybase connections per process.

sybase.max_links integer

The maximum number of Sybase connections per process, including persistent connections.

Sybase-CT Configuration Directives

sybct.allow_persistent boolean

Whether to allow persistent Sybase-CT connections. The default is on.

sybct.max_persistent integer

The maximum number of persistent Sybase-CT connections per process. The default is -1 meaning unlimited.

sybct.max_links integer

The maximum number of Sybase-CT connections per process, including persistent connections. The default is -1 meaning unlimited.

sybct.min_server_severity integer

Server messages with severity greater than or equal to sybct.min_server_severity will be reported as warnings. This value can also be set from a script by calling sybase_min_server_severity(). The default is 10 which reports errors of information severity or greater.

sybct.min_client_severity integer

Client library messages with severity greater than or equal to sybct.min_client_severity will be reported as warnings. This value can also be set from a script by calling sybase_min_client_severity(). The default is 10 which effectively disables reporting.

sybct.login_timeout integer

The maximum time in seconds to wait for a connection attempt to succeed before returning failure. Note that if max_execution_time has been exceeded when a connection attempt times out, your script will be terminated before it can take action on failure. The default is one minute.

sybct.timeout integer

The maximum time in seconds to wait for a select_db or query operation to succeed before returning failure. Note that if max_execution_time has been exceeded when am operation times out, your script will be terminated before it can take action on failure. The default is no limit.

sybct.hostname string

The name of the host you claim to be connecting from, for display by sp_who. The default is none.

BC Math Configuration Directives

bcmath.scale integer

Number of decimal digits for all bcmath functions.

Browser Capability Configuration Directives

browscap string

Name of browser capabilities file.

Unified ODBC Configuration Directives

uodbc.default_db string

ODBC data source to use if none is specified in odbc_connect() or odbc_pconnect().

uodbc.default_user string

User name to use if none is specified in odbc_connect() or odbc_pconnect().

uodbc.default_pw string

Password to use if none is specified in odbc_connect() or odbc_pconnect().

uodbc.allow_persistent boolean

Whether to allow persistent ODBC connections.

uodbc.max_persistent integer

The maximum number of persistent ODBC connections per process.

uodbc.max_links integer

The maximum number of ODBC connections per process, including persistent connections.