Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Last active July 23, 2018 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yano3nora/3a5cab019748d683980462cfa5ce87a1 to your computer and use it in GitHub Desktop.
Save yano3nora/3a5cab019748d683980462cfa5ce87a1 to your computer and use it in GitHub Desktop.
[php: Xdebug note] php famous debugging tool. #php #xdebug #vagrant #sublime

Overview

Xdebug は PHP のデバッグ拡張ツール。PHP実行環境下で var_dump 整形やステップ実行ができるようになるよやったね。IDE利用せずに Vagrant VM 下で走らせて実行結果をホストOS側エディタに出力してもらうような利用を想定。

How to Use?

  • Ctrl+F8 でブレークポイント設置/削除
  • デバッガ起動
    • CommandPallet > Xdebug StartDebugging (lounchwindow)
    • Ctrl+Shift+F9
  • Ctrl+Shift+F10 でデバッガ終了
  • Ctrl+Shift+F5 で次ブレークポイント
  • Ctrl+Shift+F6 でステップイン

References

https://liginc.co.jp/224022 http://qiita.com/hazcauch/items/d8ad88ba906982ea9589 http://qiita.com/xiao/items/9dc20689658ab5ee64af http://qiita.com/ushi_d/items/f4b5af012725728842d7 https://github.com/martomo/SublimeTextXdebug

Installation

env

  • vagrant
  • php
  • sublime text 3

process

install xdebug to guest os of vagrant

# centos
sudo yum --enablerepo=remi,epel,rpmforge,remi-php71 -y install php-pecl-xdebug

# 大体はインストールされた時に設定済みなので以下は不要
# sudo sed -i '$a\zend_extension=xdebug.so' /etc/php.d/15-xdebug.ini

sudo sed -i '$a xdebug.idekey=\"vagrant\"' /etc/php.ini
sudo sed -i '$a xdebug.remote_log=\"\/var\/log\/xdebug\/xdebug.log\"' /etc/php.ini
sudo sed -i '$a xdebug.remote_enable=1' /etc/php.ini
sudo sed -i '$a xdebug.remote_handler=\"dbgp\"' /etc/php.ini
sudo sed -i '$a xdebug.remote_mode=\"req\"' /etc/php.ini
sudo sed -i '$a xdebug.remote_host=127.0.0.1' /etc/php.ini
sudo sed -i '$a xdebug.remote_connect_back=1' /etc/php.ini
sudo sed -i '$a xdebug.remote_port=9000' /etc/php.ini
sudo sed -i '$a xdebug.remote_autostart=true' /etc/php.ini
sudo mkdir /var/log/xdebug
sudo touch /var/log/xdebug/xdebug.log
sudo chown apache:apache /var/log/xdebug
sudo chmod -R 777 /var/log/xdebug
service httpd restart

install & setting sublime package

  1. xdebugClient パッケージインストール
  2. .sublime-project の編集 (下記コード参照)
  3. sublime text 再起動
{
  "folders":
  [
    {
      "path": "."
    }
  ],
  "settings":
  {
    "default_line_ending": "unix",
    "tab_size": 2,
    "translate_tabs_to_spaces": true,
    "xdebug": {
      "ide_key": "vagrant",
      "port": 9000,
      "launch_browser": true,
      "url": "http://192.168.33.10",
      "path_mapping": {
        "/var/www" : "C:/ws/git/amp/p29_bizops",
       },
       "super_globals": true,
       "close_on_stop": true
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment