環境設定5.php.iniファイル


Apache側の設定が終わったら、次はPHP側です。当サイトではSQLiteデータベースと連動させることをメインに、設定の仕方を説明していきます。


php.iniファイル


phpの各種設定は、php5のフォルダ直下にある「php.ini」というファイルで行ないます。しかしこのファイル、phpをダウンロードしたフォルダそのものには存在しません。原本となるファイル「php.ini-xxx」が2つ入っており、このうち好きな方1つを「php.ini」に変更して使うのです。


「php5」フォルダの中にある原本ファイルのひとつを、「php.ini」ファイルに。

php.iniの設定


「php.ini-xxx」を「php.ini」に変更したら、今度はそれを「メモ帳」などのテキストエディタで開き、下記の内容を設定しましょう。ちなみに、緑の文字は注釈ですんで書き足す必要はありません。

≪ドキュメントルート≫
; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues. The alternate is to use the
; cgi.force_redirect configuration below
; http://php.net/doc-root
doc_root = "c:/Apache2.2/htdocs" ←「" "」を設定。本サイトのとおりにセッティングすると、左記のとおりになります。

≪拡張モジュール・ディレクトリ≫
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "c:/php5/ext" ←「" "」を設定。本サイトのとおりにセッティングすると、左記のとおりになります。


※拡張モジュールを格納した「ext」フォルダが、「php5」フォルダ直下にあることを確認です。

≪拡張モジュール設定≫
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
      |
extension=php_mbstring.dll ←「;」を外します。
      |
extension=php_pdo_sqlite.dll ←「;」を外します。
      |
extension=php_sqlite.dll ←「;」を外します。
extension=php_sqlite3.dll ←「;」を外します。


※拡張モジュール「xxx_dll」ファイルが、すべて「ext」フォルダ内に収納されていることを確認します。

≪タイムゾーン≫
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Tokyo"  ←「" "」を左記のとおりに設定します。

≪日本語文字列処理(UTF-8)≫
default_charset = "utf-8" ←「;」を外し、左記のとおりに設定します。
      |
[mbstring]
; language for internal character representation.
; http://php.net/mbstring.language
mbstring.language = Japanese ←「;」を外します。

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
; http://php.net/mbstring.internal-encoding
mbstring.internal_encoding = utf-8 ←「;」を外し、左記のとおりに設定します。

; http input encoding.
; http://php.net/mbstring.http-input
mbstring.http_input = auto ←「;」を外します。

; http output encoding. mb_output_handler must be
; registered as output buffer to function
; http://php.net/mbstring.http-output
mbstring.http_output = utf-8 ←「;」を外し、左記のとおりに設定します。

; enable automatic encoding translation according to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
; portable libs/applications.
; http://php.net/mbstring.encoding-translation
mbstring.encoding_translation = Off ←「;」を外します。

; automatic encoding detection order.
; auto means
; http://php.net/mbstring.detect-order
mbstring.detect_order = auto ←「;」を外します。

; substitute_character used when character cannot be converted
; one from another
; http://php.net/mbstring.substitute-character
mbstring.substitute_character = none; ←「;」を外します。

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
; http://php.net/mbstring.func-overload
mbstring.func_overload = 0 ←「;」を外します。