【PHP】PDT+XDEBUGでPHPの統合開発環境を構築(その2 各種設定)
前回からの続きです。
各プログラムのダウンロード・インストール方法は、前回のエントリを参照してください。
php.iniの編集
使用するPHPの動作設定を行うためにphp.iniを編集します。
PHPを動作させるための設定
新しくPHPを導入した環境ではphp.iniはありません。自分で作成します。
PHPをインストールしたフォルダにphp.ini-recommendedという雛形として使えるファイルがあります。(PHPのバージョンによって異なりますが、近いファイル名の物があるはずです。5.3では、php.ini-developmentです。)
この雛形ファイルを、php.iniという名前で、同じフォルダ(php.exeと同じフォルダ)にコピーします。
次にこのファイルをテキストエディタで修正します。
下記の記述箇所を見つけて先頭の;(セミコロン コメントの意味)を消して、自分の使う環境に合わせて書き換えます。
;エクステンションディレクトリのパス extension_dir = "c:\php5\ext" ...(略)... ;マルチバイト関数を使えるように... extension=php_mbstring.dll ...(略)... mbstring.language = Japanese ...(略)... ;UTF-8を主に使う場合 mbstring.internal_encoding = UTF-8 ...(略)... mbstring.http_input = pass mbstring.http_output = pass mbstring.encoding_translation = Off ...(略)... mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII
(灰色の文字は、私の付けた注釈です。)
XDebug用のphp.iniの設定
php.iniの最後に以下の記述を書き足します。
;ファイルの最後に以下の記述を追加 [XDebug] ;XDebug DLLのフルパス zend_extension_ts = "c:\php5\debugger\php_xdebug-2.0.5-5.2.dll" ;赤字の部分はスレッドセーフ版を使用でかつPHP 5.3未満のとき、zend_extension_ts ;スレッドセーフが無効のとき、または、PHP 5.3以上の場合は常に、zend_extension ;リモートデバッグ オン xdebug.remote_enable=1 ;デバッグクライアントのアドレス xdebug.remote_host="localhost" ;デバッガの通信に使うポート番号(Webサーバのポートではない) xdebug.remote_port=9000
パスは自分の環境に合わせて読み替えてください。
Apacheのhttpd.conf
(すでにApacheとPHPを使っている人は読み飛ばしてください。)
Apacheをインストールしたフォルダの下にあるconfフォルダの中にhttpd.confというファイルが入っています。これをテキストエディタで編集します。
以下の部分を編集します。(以下は、D:\MyWork にプロジェクトを保存する場合の例です。)
#htmlやphpファイルを置くフォルダのトップです。Webブラウザで見るときにルートとなるフォルダ。 #DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs" #↓変えます DocumentRoot "D:/MyWork"
#同じくルートフォルダ。フォルダの設定になります。 #<Directory "C:/Program Files/Apache Group/Apache2/htdocs"> #↓変えます <Directory "D:/MyWork">
#DirectoryIndex index.html #↓変えます DirectoryIndex index.html index.php index.phps
<IfModule>~</IfModule>の間に赤字の部分を書き足します。
<IfModule> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig conf/mime.types # # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz # # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi # For type maps (negotiated resources): #AddHandler type-map var # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # #AddType text/html .shtml #AddOutputFilter INCLUDES .shtml AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule>
ファイルの最後に以下の記述を付け足します。パスは自分の環境に、php5apache2_2.dll の部分は、使用するApacheのバージョンと同一のものに読み替えてください。
#使用するPHPの設定 Apacheのバージョンによって数字の部分が違います。 LoadModule php5_module C:/php5/php5apache2_2.dll #php.iniのあるフォルダ PHPINIDir "C:\php5"
Eclipse(PDT)の設定
PDTをインストールしたフォルダの中のeclipse.exeを起動します。
ワークスペース(プロジェクト全体の規定の保存場所みたいなもの)を入力します。
起動したら、メニューの「ウィンドウ」-「設定」で、設定ウィンドウを出します。
「PHP」-「PHP Executables」で、「Addボタン」を押して、PHPのインストール先のフォルダを指定します。
Nameに、自分でわかりやすい設定名を入れます。
Executable pathは、php.exeのフルパス(c:\php5\php.exeなど)を入れます。
php ini fileは、編集済のphp.iniのフルパス(c:\php5\php.iniなど)を入れます。
PHP debuggerは、Xdebugを選択します。
次に左のツリーから、「PHP」-「PHP Servers」を選択して、サーバーのアドレスを入力します。
Nameに好きな設定名、下の欄は、ブラウザで見たときにルートになるURLを入れます(たとえば、http://localhost:8080/)。
最後に、「PHP」-「Debug」を開きます。
PHP Debuggerは、XDebugを選択、ServerとPHP Executable Pathは、先に作ってある設定名を選択します。文字コードは、自分で使用するコード。Break at First Lineは、一行目で必ずブレークさせる場合は、チェックします。
「PHP」-「Debug」-「Installed Debuggers」で、XDebugのポートをphp.iniで設定したポート番号と合わせておいてください。
OKボタンで設定を保存します。
設定は、以上で完了です。次回のエントリで、実際にデバッガを使ってみます。
関連記事
TrackBack URL :
Comments (1)
[...] http://www.r-nakai.com/archives/209 [...]
ピンバック by GPLでクラウドファウンディング・サイトを作るんだぜ☆!(27) Xdebugを調べようぜ☆?(^~^)? – ぐれーすけーる — 2016/2/13 土曜日 @ 11:10:50