1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

同じポートにしても動かない(2019.08.30 訂正版)【Vagrant, PHPStorm, Xdebug】

Last updated at Posted at 2019-08-24

TL;DR

大いなる勘違いをしていたので訂正します。

Xdebugのポートは9001にするけど、PHPStomeのXdebug用ポート設定は9000のままにするんだ!
Xdebugのポートを9001にして、PHPStomeのXdebug用ポート設定も9001にするんだ!
9000番はphp-fpmが使っている可能性があるぞ!

環境

Vagrant: 2.2.0
ゲストOS: CentOS 7.6.1810 (Core)
Apache: 2.4.6
PHP: 5.6.38
Xdebug:2.5.5

ホストOS: Windows 10 Pro 64bit ver. 1903
PHPStorm:2019.2.1 RC
Pleiades: 2019.08.21
Chrome: 76.0.3809.100 (Official Build) 64ビット
Xdebug helper: 1.6.1

前提

  • Vagrantの仮想環境にOS、Apache、PHP、Xdebugがインストール済み
  • WindowsにPHPStorm、Chrome、Xdebuger helperがインストール済み
  • ソースコードはゲストOSにホストOSと同じものをアップロード済み

PHP の Xdebug 設定

Xdebugインストール時にphpのXdebug用設定ファイルが作成されたので、値を追記します。
php.iniへの追記でも大丈夫かもです(未検証)。

/etc/php.d/15-xdebug.ini
zend_extension = /usr/lib64/php/modules/xdebug.so ; Xdebugモジュールのパス
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = 192.168.33.1 ; デバッグ接続するPCのIPアドレス
xdebug.remote_port = 9001         ; デフォルトは 9000
xdebug.idekey = "PHPSTORM"`       ; PHPStormとのセッションクッキー名

PHPStrom側の設定

  1. メニューより[ファイル]→[設定]を開きます。
  2. [言語 & フレームワーク]→[デバッグ]を選択します。
  3. [Xdebug]→[デバッグ・ポート]の値をデフォルト値「9000」から~~変更してはいけません「9001」に変更します。iniファイルのxdebug.remote_portと合わせるとうまく動作しなくなります~~うまく動作します!。

image.png

  1. [言語 & フレームワーク]→[サーバー]を選択します。[+]でサーバーを追加します。
    1. [名前]に本設定の名前を付けます。「vagrant_server」としました。
    2. [ホスト]にドメイン or IPアドレスを入力します。「192.168.33.10」としました。Vagrantfileで設定しているものと同じIPアドレスです。
    3. [サーバ上の絶対パス]にVagrant仮想環境へアップロードした絶対パスを入力します。
  2. メニューより[実行]→[構成の編集]を選択します。
  3. 左上の[+]から、「PHP Remote Debug」を選択し、設定を追加します。
    1. [名前]に本設定の名前を付けます。「test_project」としました。
    2. [構成]→[サーバ]コンボボックスより先ほど作成したサーバー「vagrant_server」を選択します。
    3. [構成]→[Ide キー(セッション id)]にiniファイルで指定した「PHPSTORM」を入力します。ダブルクォーテーション(")は不要です。

Xdebug helperの設定

  1. Chomeのメニューより[設定]→[機能拡張]を選択します。
  2. Xdebug helperの[詳細]→[機能拡張のオプション]を選択します。設定画面が開きます。
  3. [IDE Key]の「Eclipse」を「PhpStorm」に変更し、IDEキーを「PHPSTORM」に変更します。
  4. [Save]ボタンをクリックして保存します。

以上の設定でブレークポイントが機能します。
Xdebugのポート番号とPHPStomeのポート番号を一致させると動かないとか意地悪ですねぇ…

私がどうかしてました。ガセ情報を流してスミマセン。😓

謝辞

本記事は @atchy@github 様の記事「Vagrantに構築した環境へPHPStorm + Xdebug でデバッグする」を参考に作成されました。
ありがとうございます!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?