Vagrantで起動したCentOS 5.5へXdebugをインストールしてNetBeansからリモートデバッグするまでの手順です。
PHPのインストール
PHPのインストールはこんな感じで行いました。
# yum -y install php php-mbstring php-mcrypt php-mysql
PECL、PEARのインストール
XdebugのインストールにはPECL(ピクル、PHP Extension Community Library)という拡張ライブラリが必要なのと、さらにPECLにPEAR (ペア、PHP Extension and Application Repository)が必要なのでまとめてインストールします。
# yum -y install php-devel php-pear
Xdebugのインストールでエラー
Xdebugをインストールしてみるとエラーになってしまいました。
# pecl install xdebug downloading xdebug-2.2.5.tgz ... Starting to download xdebug-2.2.5.tgz (255,840 bytes) .................................done: 255,840 bytes Validation Error: Invalid tag order in <package>, found <zendextsrcrelease> expected one of "providesextension, srcpackage, srcuri, phprelease, extsrcrelease, extbinrelease, bundle" Parsing of package.xml from file "/tmp/tmpqJZWco/package.xml" failed Download of "pecl/xdebug" succeeded, but it is not a valid package archive Error: cannot download "pecl/xdebug"
PEARのバージョンが古いのでエラーになったらしいです。
# pear list Installed packages, channel pear.php.net: ========================================= Package Version State Archive_Tar 1.3.1 stable Console_Getopt 1.2 stable PEAR 1.4.9 stable XML_RPC 1.5.0 stable
PEARをアップグレードしてみるとこちらもエラーになってしまいました。
Archive_TarとConsole_Getoptのバージョンが古いらしいです。
# pear upgrade pear WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update pear/PEAR dependency package "pear/Console_Getopt" downloaded version 1.3.1 is not the recommended version 1.2.3, but may be compatible, use --force to install pear/Archive_Tar requires PEAR Installer (version >= 1.5.4), installed version is 1.4.9 pear/Console_Getopt requires PEAR Installer (version >= 1.8.0), installed version is 1.4.9 downloading Structures_Graph-1.0.4.tgz ... Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes) .........done: 30,318 bytes downloading XML_Util-1.2.3.tgz ... Starting to download XML_Util-1.2.3.tgz (17,134 bytes) ...done: 17,134 bytes upgrade ok: channel://pear.php.net/XML_Util-1.2.3 ERROR: unable to unpack /tmp/tmprniguc/Structures_Graph-1.0.4.tgz
Archive_TarとConsole_Getoptをそれぞれアップグレードします。
# pear upgrade --force Archive_Tar WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update warning: pear/pear dependency package "pear/Archive_Tar" installed version 1.3.12 is not the recommended version 1.3.1warning: pear/Archive_Tar requires PEAR Installer (version >= 1.5.4), installed version is 1.4.9 downloading Archive_Tar-1.3.12.tgz ... Starting to download Archive_Tar-1.3.12.tgz (19,863 bytes) .......done: 19,863 bytes upgrade ok: channel://pear.php.net/Archive_Tar-1.3.12 You have new mail in /var/spool/mail/root
# pear upgrade --force Console_Getopt WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update warning: pear/Console_Getopt requires PEAR Installer (version >= 1.8.0), installed version is 1.4.9 downloading Console_Getopt-1.3.1.tgz ... Starting to download Console_Getopt-1.3.1.tgz (4,471 bytes) .....done: 4,471 bytes upgrade ok: channel://pear.php.net/Console_Getopt-1.3.1
もう一度PEARをアップグレードしてみると成功しました。
# pear upgrade pear WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update downloading PEAR-1.9.5.tgz ... Starting to download PEAR-1.9.5.tgz (290,006 bytes) .................done: 290,006 bytes downloading Structures_Graph-1.0.4.tgz ... Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes) ...done: 30,318 bytes upgrade ok: channel://pear.php.net/Structures_Graph-1.0.4 upgrade ok: channel://pear.php.net/PEAR-1.9.5 PEAR: Optional feature webinstaller available (PEAR's web-based installer) PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer) PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer) To install use "pear install pear/PEAR#featurename"
バージョンが上がったことが確認できます。
# pear list Installed packages, channel pear.php.net: ========================================= Package Version State Archive_Tar 1.3.12 stable Console_Getopt 1.3.1 stable PEAR 1.9.5 stable Structures_Graph 1.0.4 stable XML_RPC 1.5.0 stable XML_Util 1.2.3 stable
Xdebugのインストール
Xdebugのインストールに成功しました。
# pecl install xdebug +----------------------------------------------------------------------+ | | | INSTALLATION INSTRUCTIONS | | ========================= | | | | See http://xdebug.org/install.php#configure-php for instructions | | on how to enable Xdebug for PHP. | | | | Documentation is available online as well: | | - A list of all settings: http://xdebug.org/docs-settings.php | | - A list of all functions: http://xdebug.org/docs-functions.php | | - Profiling instructions: http://xdebug.org/docs-profiling2.php | | - Remote debugging: http://xdebug.org/docs-debugger.php | | | | | | NOTE: Please disregard the message | | You should add "extension=xdebug.so" to php.ini | | that is emitted by the PECL installer. This does not work for | | Xdebug. | | | +----------------------------------------------------------------------+ running: find "/tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5" | xargs ls -dils 13205692 4 drwxr-xr-x 3 root root 4096 8月 6 18:34 /tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5 13205748 4 drwxr-xr-x 3 root root 4096 8月 6 18:34 /tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5/usr13205749 4 drwxr-xr-x 3 root root 4096 8月 6 18:34 /tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5/usr/lib 13205750 4 drwxr-xr-x 3 root root 4096 8月 6 18:34 /tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5/usr/lib/php 13205751 4 drwxr-xr-x 2 root root 4096 8月 6 18:34 /tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5/usr/lib/php/modules 13205747 592 -rwxr-xr-x 1 root root 600654 8月 6 18:34 /tmp/pear/temp/pear-build-root9X5toQ/install-xdebug-2.2.5/usr/lib/php/modules/xdebug.so Build process completed successfully Installing '/usr/lib/php/modules/xdebug.so' Release Warnings ================ p install ok: channel://pecl.php.net/xdebug-2.2.5 configuration option "php_ini" is not set to php.ini location You should add "zend_extension=/usr/lib/php/modules/xdebug.so" to php.ini
php.iniの設定
php.iniファイルの最後の行にXdebugの設定を追記します。
# vi /etc/php.ini
zend_extension="/usr/lib/php/modules/xdebug.so" xdebug.remote_enable=1 xdebug.remote_connect_back=1
“remote_connect_back”ではなく、”remote_host”を使用する場合は下記のようにします。
zend_extension="/usr/lib/php/modules/xdebug.so" xdebug.remote_enable=1 xdebug.remote_host=10.0.2.2
「10.0.2.2」はVirtual Boxのネットワークアダプターの設定が「NAT」に設定されているときにゲストOS側から見たホストOS側のIPアドレスです。
Apacheを再起動して設定が反映していることを確認します。
# service httpd restart httpd を停止中: [ OK ] httpd を起動中: [ OK ] # php -i | grep xdebug.remote xdebug.remote_autostart => Off => Off xdebug.remote_connect_back => On => On xdebug.remote_cookie_expire_time => 3600 => 3600 xdebug.remote_enable => On => On xdebug.remote_handler => dbgp => dbgp xdebug.remote_host => localhost => localhost xdebug.remote_log => no value => no value xdebug.remote_mode => req => req xdebug.remote_port => 9000 => 9000
NetBeansからリモートデバッグ
Vagrantfileを編集して、vagrantのフォルダがドキュメントルートに配置されるようにします。
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "CentOS" config.vm.network "forwarded_port", guest: 80, host: 80 config.vm.synced_folder ".", "/var/www/html" end
vagrantのフォルダ内にphpinfo.phpファイルを作成します。
これで”http://localhost/phpinfo.php”にアクセスするとPHPの情報が表示されます。
<?php phpinfo();
NetBeansでvagrantのフォルダをソースフォルダに指定して新規プロジェクトを作成します。
phpinfo.phpファイルを開いて”phpinfo();”の行にブレークポイントを置きます。
デバッグ実行すると…
ブレークポイントを置いた行で止まりました!
F5キーを押して進めるとPHPの情報が表示されました。
無事NetBeansからリモートデバッグができました。
コメント