且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在MacOS上为PHPStorm安装Xdebug

更新时间:2023-01-14 22:41:22

问题

主要问题是Apple在 macOS Catalina中删除了/usr/include ,该位置曾经是任何C头文件的位置,但仍在大多数上> * NIX 系统.尝试安装任何依赖于该特定位置中的头文件的内容将失败.解决方案是手动编译 Xdebug ,指定头文件的实际位置,而这些头文件仍然由Xcode提供,而只是在完全不同的位置.

The Problem

The main problem is that Apple removed /usr/include in macOS Catalina, which had been the location for any C header file and still is on most any *NIX system. Attempting to install anything that relies on header files being within that specific location will fail miserably. The solution is to compile Xdebug manually, specifying the actual location of the header files, which are still provided by Xcode, just in an entirely different place.

1)下载 Xcode

2)打开 Xcode ,如果出现提示,请同意条款,然后退出.

2) Open Xcode, agree to terms if prompted, then quit.

3)安装完成后,打开终端:

3) Once installed open up Terminal:

$ xcode-select --install

4)验证是否找到 SDK .

$ xcrun --show-sdk-path

它应该类似于下面的路径;您稍后可能需要相应地编辑路径:

It should look similar to the path below; you might need to edit the path accordingly later on:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

手动编译Xdebug

到目前为止,版本2.9.4似乎是最新的,因此我们将克隆该版本以进行编译.

Manually Compile Xdebug

As of this moment version 2.9.4 seems to be the latest, so we'll clone that version to compile.

$ git clone https://github.com/xdebug/xdebug.git
$ cd xdebug
$ git tag -l
$ git checkout tags/2.9.4

phpize

接下来,我们需要复制 phpize ,然后编辑包含路径:

$ cp /usr/bin/phpize .
$ nano ./phpize

查找此行( Control + W ):

includedir="`eval echo ${prefix}/include`/php"

用此行替换它:

includedir="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php"

运行phpize:

$ ./phpize

正确的输出与此类似:

Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731

配置和建立

$ ./configure --enable-xdebug

完成后,运行 make ,将SDK位置定义为编译器标志.使用变量存储SDK的路径,以便在更改时更易于

After that's finished run make with the SDK location defined as compiler flags. Use a variable to store the path to the SDK so it's easier to edit if it changes:

$ SDK_PATH=$(xcrun --show-sdk-path)
$ make CPPFLAGS="-I${SDK_PATH}/usr/include/php -I${SDK_PATH}/usr/include/php/main -I${SDK_PATH}/usr/include/php/TSRM -I${SDK_PATH}/usr/include/php/Zend -I${SDK_PATH}/usr/include/php/ext -I${SDK_PATH}/usr/include/php/ext/date/lib"

可能会有警告-暂时将其忽略.最后,运行:

There maybe warnings - just ignore it for now. Finally, run:

$ make install

此命令将失败,因为它无法将扩展名移到正确的位置; SIP 阻止了它.我们将在下一步中手动移动它.仍然需要 make install ,因为它对 *.so 文件进行了代码签名.

This command will fail because it can't move the extension to the right place; SIP prevents it. We'll take care of moving it manually at the next step. make install is still required as it codesigns the *.so file.

一旦 make install 运行(并失败),我们就可以移动可执行文件:

Once make install has been run (and fails), we can move the executable:

$ sudo mkdir -p /usr/local/php/extensions
$ sudo cp $(php-config --extension-dir)/xdebug.so /usr/local/php/extensions

现在编辑PHP配置( php.ini )以启用 Xdebug :

Now edit the PHP configuration (php.ini) to enable Xdebug:

$ sudo nano /etc/php.ini

在底部添加以下内容:

[xdebug]
zend_extension=/usr/local/php/extensions/xdebug.so
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000

重新启动apache :

$ sudo apachectl restart

最后测试一切正常:

$ php -i | grep "xdebug support"

注意事项:感谢Louis Charette研究并找到了解决此问题的方法.

Notes: Thanks to Louis Charette for researching and finding a solution to this issue.

在MacOS Catalina 10.15上安装Xdebug