macOSでXDebugのインストールが失敗する

カテゴリ: 未分類 | タグ: , ,

macOSでホストOSにphp8.1とXdebugをインストールしようとしたらエラーしたので対処した時の手順を書いておきます。

環境

  • php8.1はbrewでインストール
  • macは今回、M1ではなくてIntelのものを使用(2018年のもの)
sw_vers

ProductName:    macOS
ProductVersion: 12.3
BuildVersion:   21E230
php --version

PHP 8.1.5 (cli) (built: Apr 16 2022 00:14:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
clang --version

Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

発生したエラー

sudo pecl install xdebugでXDebug3をインストールしようとしたところ、下記のmkdir()エラーが発生した。

$ sudo pecl install xdebug

downloading xdebug-3.1.4.tgz ...
Starting to download xdebug-3.1.4.tgz (231,747 bytes)
.................................................done: 231,747 bytes
93 source files, building
running: phpize
Configuring for:
PHP Api Version:         20210902
Zend Module Api No:      20210902
Zend Extension Api No:   420210902

...

running: find "/private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4" | xargs ls -dils
1237905   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4
1238554   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr
1238555   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local
1238556   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local/Cellar
1238557   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local/Cellar/php
1238558   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5
1238559   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5/pecl
1238560   0 drwxr-xr-x  3 root  wheel      96 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5/pecl/20210902
1238561 768 -rwxr-xr-x  1 root  wheel  391032 May  5 14:38 /private/tmp/pear/temp/pear-build-root6AnVVO/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5/pecl/20210902/xdebug.so

Build process completed successfully
Installing '/usr/local/Cellar/php/8.1.5/pecl/20210902/xdebug.so'

Warning: mkdir(): File exists in System.php on line 294
PHP Warning:  mkdir(): File exists in /usr/local/Cellar/php/8.1.5/share/php/pear/System.php on line 294

Warning: mkdir(): File exists in /usr/local/Cellar/php/8.1.5/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/8.1.5/pecl/20210902

ログを見ると/usr/local/Cellar/php/8.1.5/pecl/20210902を作成しようとしている。

原因

ログに書かれていたディレクトリ/usr/local/Cellar/php/8.1.5/peclを確認すると、/usr/local/lib/php/peclへのシンボリックリンクになっていた。

$ ls -l /usr/local/Cellar/php/8.1.5/pecl

lrwxr-xr-x  1 user  admin  23 Apr 29 18:31 /usr/local/Cellar/php/8.1.5/pecl -> /usr/local/lib/php/pecl

だが、リンク先の/usr/local/lib/php/peclが存在しておらず、エラーになっていた

$ ls -l /usr/local/lib/php/pecl         

ls: /usr/local/lib/php/pecl: No such file or directory

対応

/usr/local/Cellar/php/8.1.5/peclを削除して対応した。

(今回は行ってないけど、/usr/local/lib/php/peclを作る方向で対応したほうが適切だったかもしれない)

$ rm /usr/local/Cellar/php/8.1.5/pecl
$ pecl install xdebug

downloading xdebug-3.1.4.tgz ...
Starting to download xdebug-3.1.4.tgz (231,747 bytes)

...

running: find "/private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4" | xargs ls -dils
1239413   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4
1240057   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr
1240058   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local
1240059   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local/Cellar
1240060   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local/Cellar/php
1240061   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5
1240062   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5/pecl
1240063   0 drwxr-xr-x  3 user  wheel      96 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5/pecl/20210902
1240064 768 -rwxr-xr-x  1 user  wheel  390992 May  5 14:49 /private/tmp/pear/temp/pear-build-a9LtY2z/install-xdebug-3.1.4/usr/local/Cellar/php/8.1.5/pecl/20210902/xdebug.so

Build process completed successfully
Installing '/usr/local/Cellar/php/8.1.5/pecl/20210902/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.1.4
Extension xdebug enabled in php.ini

ログの最後にExtension xdebug enabled in php.iniとあるように、installするだけでXDebugのextentionが有効にされる。

有効になっているかの確認は、php --versionを実行して、with Xdebugが出ているかを見れば良い。

$ php --version

PHP 8.1.5 (cli) (built: Apr 16 2022 00:14:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
    with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans

他にphp -mで確認しても良い。

$ php -m

...
[Zend Modules]
Xdebug
Zend OPcache

補足

スタティックリンクの状態

インストール後に確認したところ、/usr/local/Cellar/php/8.1.5/peclはリンクではなく、普通のディレクトリになっていた。

xdebug.soの場所

xdebug.soファイルは下記の場所に存在している。

$ ls /usr/local/Cellar/php/8.1.5/pecl/20210902/xdebug.so 

/usr/local/Cellar/php/8.1.5/pecl/20210902/xdebug.so

iniファイルでのextension定義

php.iniの先頭行に、extension読み込みの定義が増えていた

$ head -6 /usr/local/etc/php/8.1/php.ini

zend_extension="xdebug.so"
[PHP]

;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;

常に有効になるので、これが困る場合、は別のファイルに書いておくとちょっと便利になる。
php.iniがある場所を確認すると、/usr/local/etc/php/8.1/conf.dディレクトリが用意されている。
なので、この下に../conf.d/ext-xdebug.iniといった感じで用意しておけば、機能の有効/無効を少し切り替えしやすくなる。


Amazonでおトクに買い物する方法
AmazonチャージでポイントGET


Amazonは買いもの前にAmazonギフト券をチャージしてポイントをゲットしないと損!

こちらもおススメ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です