LoginSignup
1
2

More than 1 year has passed since last update.

2023年だがVSCodeでPHP5.6環境でxdebugを使用できるようにする

Last updated at Posted at 2023-04-06

2023年だがVSCodeでPHP5.6でxdebugを使用できるようにする

背景

  • 案件の関係でUbuntu20.04にphp5.6を入れているが、xdebugを使いたかったため入れてみる。

参考

  • こちらを参考にさせていただきましたが、自分の環境ではいろいろ足りなかったので、補足しながら記述していきます。

環境

Ubuntu20.04
PHP5.6

手順

autoconfのインストール

  • 普通にxdebugをインストールしようとすると古すぎてpeclではインストールできず、ソースインストールもphpizeのautoconfで失敗するとのことでソースに必要なautoconfからインストールを始めます。

  • downloadsディレクトリを作成しautoconfをインストールし展開

cd /
mkdir downloads
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-latest.tar.gz
  • 展開したディレクトリに移動
cd autoconf-2.71
  • configureファイルを作成
./configure --prefix=/usr/local
  • 次にmakeファイルを作成するがmakeコマンドが無いと怒られたのでインストール
apt install make
  • makeファイルを作成
make
  • インストール
sudo make install

Xdebug2.5.5をインストール

  • downloadsディレクトリに戻りXdebugをダウンロード
cd /downloads
curl -OL https://xdebug.org/files/xdebug-2.5.5.tgz
tar xzf xdebug-2.5.5.tgz
cd xdebug-2.5.5
  • 次にconfigureファイルを作成するためにphpizeコマンドを使用しようとしたがないと怒られたのでインストール
apt install php5.6-dev
  • configureファイルを作成
phpize
  • configureを実行
./configure
  • makeファイルを作成
make
  • インストール
sudo make install
  • 結果は下記となるがその時に/usr/lib/php/20131226/を記憶しておく。
Installing shared extensions:     /usr/lib/php/20131226/

  +----------------------------------------------------------------------+
  |                                                                      |
  |   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.                                                            |
  |                                                                      |
  +----------------------------------------------------------------------+

Xdebugの設定

  • XdebugをPHP5.6で使用できるように設定していきます。

  • php.iniを編集

sudo vim /etc/php/5.6/apache2/php.ini
  • zend_extensionに先ほどインストールしたxdebugのパスを設定(パスは先ほど記憶したパス)
zend_extension=/usr/lib/php/20131226/xdebug.so
  • その他の設定も行う
    ※xdebug3と設定が違うので注意
zend_extension=/usr/lib/php/20131226/xdebug.so

[xdebug]
; Xdebugの機能を有効化
xdebug.remote_enable=1
; PHPの実行時にデバッグを自動的に開始する
xdebug.remote_autostart=1
; 接続先ホスト
xdebug.remote_host=localhost
; 接続先ポート
xdebug.remote_port=9003
  • apacheの再起動
sudo service apache2 stop
sudo service apache2 start
  • 年のためphpinfoを確認すると設定できている
    image.png

VSCodeのlaunch.jsonを設定

"configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html/対象ディレクトリ名": "${workspaceRoot}"
            },
        },
1
2
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
2