在MacOS Catalina 10.15上安装Xdebug [英] Installation of Xdebug on MacOS Catalina 10.15

查看:218
本文介绍了在MacOS Catalina 10.15上安装Xdebug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在OS X 10.15上安装Xdebug并遇到以下问题:

I tried to install Xdebug on OS X 10.15 and run into following problem:

/private/tmp/pear/install/xdebug/xdebug.c:25:10:致命错误:未找到"php.h"文件

/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: 'php.h' file not found

我试图解决此处所述的问题:在MacOs Mojave上安装xdebug-找不到'php.h'文件

I tried to fix the problem like described here: Installing xdebug on MacOs Mojave - 'php.h' file not found

不幸的是,在以下目录中找不到头文件:/Library/Developer/CommandLineTools/Packages

Unfortunately the header files cannot be found in this directory: /Library/Developer/CommandLineTools/Packages

有什么想法可以获取OS X 10.15的当前头文件?

Any ideas where I can get the current header files for OS X 10.15?

推荐答案

tl; dr

Apple决定删除/usr/includemacOS_SDK_headers_for_macOS_10.14.pkg程序包中的头文件.要安装Xdebug,必须在phpizemake中使用正确的引用手动编译Xdebug.

tl;dr

Apple decided to remove headers file in /usr/include and the macOS_SDK_headers_for_macOS_10.14.pkg package. To install Xdebug, you'll have to manually compile Xdebug with the correct reference in both phpize and make.

有关更多详细信息,我写了一篇有关问题的博客文章, 解决方案

For more details, I wrote a blog article about the issue and the solution

长话短说,Apple决定在MacOS Catalina中取消/usr/include的功能,该位置一直是UNIX系统中C头文件的默认位置.尝试通过PEAR/PECL安装将返回错误,因为编译器将在/usr/include中寻找必要的头文件.因此,解决方案是手动编译Xdebug,手动指定头文件的实际位置,这些头文件仍然由Xcode提供,位于其他位置.

Long story short, Apple decided to nuke /usr/include in MacOS Catalina, which has been the default location for C header file for ever in UNIX systems. Trying to install through PEAR / PECL will return an error as the compiler will look for necessary headers file in /usr/include. So the solution is to compile Xdebug manually, manually specifying the actual location of the header files, which are still provided by Xcode, just at a different location.

首先,确保已安装Xcode,包括命令行工具.以下命令将显示默认SDK的位置:

First, make sure Xcode is installed, including the command line tools. The following command will display the location of the default SDK :

$ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

您想要的标题(php.h)将位于/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main中.

The header you'll want (php.h) will then be in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main.

让我们编译 2.7.2 ,从git获取源代码.另外,您可以从 Xdebug网站下载源代码.

Let's compile 2.7.2, getting the source code from git. Alternatively, you can download the source from Xdebug site.

git clone https://github.com/xdebug/xdebug.git
cd xdebug
git checkout tags/2.7.2

phpize

接下来,我们需要制作一个副本phpize,以便我们可以编辑包含路径:

phpize

Next we need to make a copy phpize so we can edit the include path :

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

找到此行:

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

...并将其替换为此行:

...and replace it with this line :

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

运行phpize:

./phpize

您现在应该看到类似这样的内容:

You should now see something like this :

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

配置和构建

我们现在可以配置:

Configure & build

We can now configure :

./configure --enable-xdebug

...并使用定义为编译器标志的自定义SDK位置运行make:

...and run make using our custom SDK location defined as compiler flags :

make CPPFLAGS='-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/TSRM -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/Zend -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext/date/lib'

可能会看到一些警告,请暂时将其忽略.最后,我们需要运行:

Might see some warning, just ignore it for now. Finally, we'll need to run :

make install

同样,此命令将失败,因为它无法将扩展名移至正确的位置. SIP将阻止它.但是不用担心,我们将在下一步中手动进行处理.仍然需要进行安装,因为它将签名* .so文件.

Again, this command will fail because it can't move the extension to the right place. SIP will prevent it. But no worries, we'll take care of that manually at the next step. make install is still required as it will sign the *.so file.

接下来,我们将可执行文件移到安全的地方.我使用/usr/local/php/extensions.

Next, we move the executable somewhere safe. I use /usr/local/php/extensions.

sudo mkdir -p /usr/local/php/extensions
sudo cp /usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so /usr/local/php/extensions

然后,我们编辑PHP配置以启用Xdebug.只需编辑php.ini:

Then we edit the PHP configuration to enable Xdebug. Simply edit php.ini:

sudo nano /etc/php.ini

然后在底部添加以下内容:

And we add the following at the bottom :

[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

重新启动内置服务器以确保:

Restart built in server to be sure :

sudo apachectl restart

最后测试一切正常:

php -i | grep "xdebug support"

如果以上命令未返回任何内容,则说明Xdebug在您的安装中不可用.返回步骤以找出缺少的内容.

If the above command returns nothing, then Xdebug is not available on your install. Go back the steps to find out what's missing.

一个更完整的解决方法是编辑php-config --include-dir的结果,该结果返回/usr/include/php.这样一来,任何安装都无需手动编辑文件或编译器标志即可找到必要的头文件.

A more complete fix would be to edit the result of php-config --include-dir, which returns /usr/include/php. That would make any installation find the necessary header files without having to manually edit files or compiler flags.

这篇关于在MacOS Catalina 10.15上安装Xdebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆