📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)
編集の要約なし |
|||
| (同じ利用者による、間の13版が非表示) | |||
| 22行目: | 22行目: | ||
==== パッケージ管理システムからインストール ==== | ==== パッケージ管理システムからインストール ==== | ||
以下のコマンドを実行する。<br> | 以下のコマンドを実行する。<br> | ||
# | # RHEL | ||
sudo | sudo dnf install php84-php-pecl-xdebug3.x86_64 # PHP 8.4の場合 | ||
php83-php-pecl-xdebug3.x86_64 # PHP 8.3の場合 | |||
# | php82-php-pecl-xdebug3.x86_64 # PHP 8.2の場合 | ||
php81-php-pecl-xdebug3.x86_64 # PHP 8.1の場合 | |||
php81-php-pecl-xdebug3.x86_64 # PHP 8.0の場合 | |||
php74-pecl-xdebug3.x86_64 # PHP 7.4の場合 | |||
# SUSE | # SUSE | ||
sudo zypper install php7-xdebug | sudo zypper install php8-xdebug # PHP 8の場合 | ||
php7-xdebug # PHP 7の場合 | |||
<br> | <br> | ||
==== ソースコードからインストール ==== | ==== ソースコードからインストール ==== | ||
| 55行目: | 58行目: | ||
<br> | <br> | ||
===== Xdebugのインストール ===== | ===== Xdebugのインストール ===== | ||
まず、[https://xdebug.org/download Xdebugの公式Webサイト] | まず、[https://xdebug.org/download Xdebugの公式Webサイト]にアクセスして、Xdebugのソースコードをダウンロードする。<br> | ||
ダウンロードしたファイルを解凍する。<br> | |||
tar xf xdebug-<バージョン名>.tgz | tar xf xdebug-<バージョン名>.tgz | ||
cd xdebug-<バージョン名> | |||
<br> | <br> | ||
<code>phpize</code>コマンドを実行する。<br> | |||
phpize | phpize | ||
<br> | <br> | ||
Xdebugをビルドおよびインストールする。<br> | |||
もし、<code>configure</code>スクリプトの実行に失敗する場合、Xdebugのビルドに必要なライブラリ等が不足している。<br> | |||
mkdir xdebug-build && cd xdebug-build | |||
./configure --enable-xdebug | ../configure \ | ||
< | --enable-xdebug \ | ||
--enable-xdebug-dev \ # 任意 | |||
--prefix=<PHPのインストールディレクトリ> # PHPを任意のディレクトリにインストールしている場合等に指定する | |||
make -j $(nproc) | make -j $(nproc) | ||
make install | |||
または | |||
sudo make install | |||
<br> | <br> | ||
インストールしたxdebug.soファイルの場所は、各LinuxディストリビューションやPHPの環境により異なる。<br> | |||
<br> | <br> | ||
RHELおよびSUSEにおいて、パッケージ管理システムからPHPをインストールした場合は、/usr/lib64/php<PHPのバージョン>/extensionsディレクトリに配置される。<br> | |||
ソースコードからPHPをインストールした場合は、/<PHPのインストールディレクトリ>/lib64/extensions/xxxディレクトリ等に配置される。<br> | |||
<br><br> | <br><br> | ||
| 84行目: | 92行目: | ||
<br> | <br> | ||
<u>Xdebugのバージョンにより、[xdebug]セクションの設定が異なることに注意すること。</u><br> | <u>Xdebugのバージョンにより、[xdebug]セクションの設定が異なることに注意すること。</u><br> | ||
# | # RHEL | ||
sudo vi /etc/php.d/15-xdebug.ini | sudo vi /etc/php.d/15-xdebug.ini # PHPをパッケージ管理システムからインストールしている場合 | ||
sudo vi /<PHPのインストールディレクトリ>/etc/conf.d/xdebug.ini # PHPをソースコードからインストールしている場合 | |||
# SUSE | # SUSE | ||
sudo vi /etc/ | sudo vi /etc/php<span style="color: #C00000">X</span>/conf.d/xdebug.ini # PHPをパッケージ管理システムからインストールしている場合 <span style="color: #C00000">X</span>はPHPのバージョン | ||
sudo vi /<PHPのインストールディレクトリ>/etc/conf.d/xdebug.ini # PHPをソースコードからインストールしている場合 | |||
<br> | <br> | ||
* Xdebug 3.xの設定 | * Xdebug 3.xの設定 | ||
*: Xdebug 3.xの標準ポート番号は、9003番に変更されたことに注意すること。 | |||
*: <code>xdebug.remote_host</code>は、<code>xdebug.client_host</code>に置き換えられた。 | |||
*: <code>xdebug.remote_port</code>は、<code>xdebug.client_port</code>に置き換えられた。 | |||
*: <code>xdebug.remote_log</code>は、<code>xdebug.log</code>に置き換えられた。 | |||
*: これは Step Debugging以外のログメッセージも含まれる。 | |||
*: <br> | |||
*: <code>xdebug.remote_mode</code>は、以下に示す設定に置き換えられた。 | |||
*:: <code>xdebug.remote_mode=req</code>(デフォルト値)の場合は、<code>xdebug.mode=debug</code>と<code>xdebug.start_with_request=trigger</code>を使用する。 | |||
*:: <code>xdebug.remote_autostart</code>の動作が必要な場合は、<code>xdebug.start_with_request=trigger</code>の代わりに<code>xdebug.start_with_request=yes</code>を使用する。 | |||
*:: <code>xdebug.start_with_request=jit</code>の場合は、<code>xdebug.mode=debug</code>および<code>xdebug.start_upon_error=yes</code>を使用する。 | |||
# 1行目を編集 | # 1行目を編集 | ||
zend_extension = <配置したxdebug.soファイルのフルパス> | zend_extension = <配置したxdebug.soファイルのフルパス> | ||
| 99行目: | 120行目: | ||
xdebug.start_with_request=yes | xdebug.start_with_request=yes | ||
xdebug.dump_undefined=1 | xdebug.dump_undefined=1 | ||
xdebug. | xdebug.log="<出力したいログファイルのフルパス 例. /home/user/xdebug.log>" | ||
xdebug.remote_handler=dbgp | xdebug.remote_handler=dbgp | ||
xdebug. | xdebug.client_port=9003 ; 標準は9003番ポート | ||
xdebug.client_host=127.0.0.1 | |||
xdebug.idekey=VSCODE | xdebug.idekey=VSCODE | ||
<br> | <br> | ||
* Xdebug 2.xの設定 | * Xdebug 2.xの設定 | ||
: Xdebug 2.xの標準ポート番号は、9000番であることに注意すること。 | |||
# 1行目を編集 | # 1行目を編集 | ||
zend_extension = <配置したxdebug.soファイルのフルパス> | zend_extension = <配置したxdebug.soファイルのフルパス> | ||
| 124行目: | 143行目: | ||
xdebug.idekey=VSCODE | xdebug.idekey=VSCODE | ||
<br> | <br> | ||
xdebug. | xdebug.iniファイルの設定を反映させるため、Apache2またはNginXを再起動する。<br> | ||
sudo systemctl restart apache2 | sudo systemctl restart apache2 | ||
または | または | ||
sudo systemctl restart | sudo systemctl restart nginx | ||
<br><br> | <br><br> | ||
| 255行目: | 274行目: | ||
*# 検索項目に"xDebug Helper"と入力して、xDebug Helperをインストールする。 | *# 検索項目に"xDebug Helper"と入力して、xDebug Helperをインストールする。 | ||
<br><br> | <br><br> | ||
== リモートデバッグ == | |||
==== リモートサーバ側の設定 ==== | |||
Xdebugの設定ファイルに、以下の設定を追記する。<br> | |||
sudo vi /etc/php7/conf.d/xdebug.ini | |||
<br> | |||
# /etc/php7/conf.d/xdebug.iniファイル | |||
[xdebug] | |||
xdebug.mode=debug | |||
xdebug.start_with_request=yes | |||
xdebug.dump_undefined=1 | |||
xdebug.remote_enable=1 | |||
xdebug.remote_autostart=1 | |||
xdebug.remote_log=<デバッグ用ログファイルのフルパス> ; 例 : /tmp/xdebug.log | |||
xdebug.remote_host=<開発PCのIPアドレス> ; 例 : 192.168.1.0/24 | |||
xdebug.remote_port=<任意のポート番号> ; 例 : 9000 | |||
xdebug.remote_handler=dbgp | |||
xdebug.remote_mode=req | |||
xdebug.client_port=9000 | |||
; xdebug.client_host=127.0.0.1 | |||
xdebug.idekey=VSCODE | |||
<br> | |||
次に、SSHの設定ファイルに、以下の設定を追記する。<br> | |||
SSHが未インストールまたは未設定の場合、[[設定 - SSH]]のページを参照すること。<br> | |||
sudo vi /etc/ssh/sshd_config | |||
<br> | |||
# /etc/ssh/sshd_configファイル | |||
GatewayPorts yes | |||
<br> | |||
設定後、SSHサービスを再起動する。<br> | |||
sudo systemctl restart sshd | |||
<br> | |||
==== 開発用PCの設定 ==== | |||
まず、リモートサーバにあるPHPプロジェクト(ドキュメントルートにあるファイル)を開発用PCにコピーする。<br> | |||
rsync -avz --rsync-path="sudo rsync" --delete --rsh="ssh" <リモートサーバのユーザ名>@<リモートサーバのIPアドレス>:<ドキュメントルートのフルパス> <開発用PCのPHPプロジェクトのフルパス> | |||
<br> | |||
次に、リモートサーバと開発環境の間にSSHトンネルを作成する。<br> | |||
ターミナルよりもVSCode等のIDE付属ターミナルで実行する方が便利である。<br> | |||
ssh -R <VSCode等のIDEで設定する任意のポート番号>:<開発用PCのIPアドレス>:<xdebug.remote_portで設定したポート番号> <リモートサーバのユーザ名>@<リモートサーバのIPアドレス> | |||
# 例 | |||
ssh -R 9000:192.168.1.10:9000 hoge@192.168.1.20 | |||
<br> | |||
VSCodeで開発を行う場合、VSCodeからPHP Debug拡張機能をインストールする。<br> | |||
launch.jsonファイルに、以下の設定を追記する。<br> | |||
<syntaxhighlight lang="json"> | |||
// ...略 | |||
{ | |||
"name": "Listen for XDebug", | |||
"type": "php", | |||
"request": "launch", | |||
"port": <上記のsshコマンドで設定した任意のポート番号>, | |||
"log": true, | |||
"pathMappings": { | |||
"<Webサーバのドキュメントルートのフルパス>": "${workspaceFolder}" | |||
} | |||
} | |||
// ...略 | |||
</syntaxhighlight> | |||
<br> | |||
最後に、PHPプロジェクトがデバッグできるかどうか確認する。<br> | |||
<br><br> | |||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ: | [[カテゴリ:RHEL]][[カテゴリ:SUSE]][[カテゴリ:Web]] | ||