OS X 10.9 Mavericks 上的 PHP Xdebug

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19579401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:44:33  来源:igfitidea点击:

PHP Xdebug on OS X 10.9 Mavericks

phpxdebugosx-mavericks

提问by greyfox

I'm having issues setting up my PHP development environment on OS X after installing OS X 10.9 Mavericks.

安装 OS X 10.9 Mavericks 后,我在 OS X 上设置 PHP 开发环境时遇到问题。

Here is the command I am using to install.

这是我用来安装的命令。

sudo pecl install xdebug

downloading xdebug-2.2.3.tgz ...
Starting to download xdebug-2.2.3.tgz (250,543 bytes)
.....................................................done: 250,543 bytes
66 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize' failed

Anyone have a solution or a workaround?

任何人都有解决方案或解决方法?

回答by Creaforge

The fast copy-paste way

快速复制粘贴方式

sudo sh -c 'echo zend_extension=$(find /usr/lib/php/extensions -name "xdebug.so") >> $(php -qr "echo php_ini_loaded_file();") && apachectl restart'

This command do the following :

此命令执行以下操作:

  • Finds the native Xdebug extension that comes with Xcode
  • Asks php which config file is loaded
  • Adds the Xdebug extension path in the config file
  • Restarts apache.
  • 查找 Xcode 自带的原生 Xdebug 扩展
  • 询问 php 加载了哪个配置文件
  • 在配置文件中添加 Xdebug 扩展路径
  • 重启apache。

Compatible with Sierra, El Capitan & Yosemite with the bundeled apache, but untested with MAMP & XAMPP.

与带有捆绑的 apache 的 Sierra、El Capitan 和 Yosemite 兼容,但未经 MAMP 和 XAMPP 测试。

Before launching the command, make sure Xcode command line tools are installed : xcode-select --install

在启动命令之前,请确保已安装 Xcode 命令行工具: xcode-select --install

回答by Dmitry Minkovsky

Don't know about using pecl. Getting Xdebug after an OS X install is pretty straightforward without pecl. You've got two easy options:

不知道怎么用pecl。在 OS X 安装后获取 Xdebug 非常简单,无需pecl. 您有两个简单的选择:

  1. Use the version already available at:

    /usr/lib/php/extensions/no-debug-non-zts-2010052/xdebug.so
    
  2. Build your own:

    1. Make sure you have the Xcode CLI tools: xcode-select --installwill prompt you to install the CLI tools. With the CLI tools installed, there should be stuff inside /usr/include/php.

    2. Go to http://xdebug.org/download.phpand download the source tarball for the version of Xdebug you want. For example: http://xdebug.org/files/xdebug-2.2.3.tgz.

    3. Extract the tarball and cdinto the directory it created. Inside that directory you'll see a README. From here it's:

      $ phpize
      Configuring for:
      PHP Api Version:         20100412
      Zend Module Api No:      20100525
      Zend Extension Api No:   220100525
      $ ./configure --enable-xdebug
      checking for grep that handles long lines and -e... /usr/bin/grep
      checking for egrep... /usr/bin/grep -E
      checking for a sed that does not truncate output... /usr/bin/sed
      [... output ...]
      $ make
      [... output ...]
      
  1. 使用已在以下位置提供的版本:

    /usr/lib/php/extensions/no-debug-non-zts-2010052/xdebug.so
    
  2. 建立你自己的:

    1. 确保您拥有 Xcode CLI 工具:xcode-select --install将提示您安装 CLI 工具。安装 CLI 工具后,里面应该有东西/usr/include/php

    2. 转到http://xdebug.org/download.php并下载您想要的 Xdebug 版本的源代码 tarball。例如:http: //xdebug.org/files/xdebug-2.2.3.tgz

    3. 将 tarball 解压缩cd到它创建的目录中。在该目录中,您将看到一个README. 从这里是:

      $ phpize
      Configuring for:
      PHP Api Version:         20100412
      Zend Module Api No:      20100525
      Zend Extension Api No:   220100525
      $ ./configure --enable-xdebug
      checking for grep that handles long lines and -e... /usr/bin/grep
      checking for egrep... /usr/bin/grep -E
      checking for a sed that does not truncate output... /usr/bin/sed
      [... output ...]
      $ make
      [... output ...]
      

Your built xdebug.sois now at modules/xdebug.so. The phpizeis critical to do with XCode CLI tools installed, because phpizesets up the build parameters for your version of PHP.

您的构建xdebug.so现在位于modules/xdebug.so。这phpize对于安装 XCode CLI 工具至关重要,因为phpize为您的 PHP 版本设置构建参数。

With your xdebug.soin hand from (1) or (2) above, you can add this block to the php.inibeing used by your phpor php-fpm:

有了xdebug.so上面的 (1) 或 (2) 的手,您可以将此块添加到php.ini您的phpor 使用的对象中php-fpm

[Xdebug]
zend_extension=<full_path_to_xdebug.so>
xdebug.remote_enable=1
xdebug.remote_host=<host running PHP (e.g. localhost)>
xdebug.remote_port=<port Xdebug tries to connect to on the host running PHP (default 9000)>

回答by wal5hy

There are two issues here. The first is that you need to install Xcode command line tools with the command:

这里有两个问题。首先是您需要使用以下命令安装 Xcode 命令行工具:

xcode-select --install

This will mean that the files previously not found in /usr/include/php/will be available.

这意味着以前找不到的文件/usr/include/php/将可用。

The next step is to install autoconfin the same way as Ares shows in his answer.

下一步是autoconf按照 Ares 在他的回答中显示的相同方式进行安装。

I would cdinto your download folder first

我会先cd进入你的下载文件夹

cd ~/Downloads/
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-latest.tar.gz
cd autoconf-*
./configure --prefix=/usr/local
make
sudo make install

now you can run the pecl installcommand

现在你可以运行pecl install命令

sudo pecl install xdebug

回答by oabarca

If you are using Mac Yosemite 10.10 and none of the above answers solved the problem. Do the following:

如果您使用的是 Mac Yosemite 10.10 并且上述答案均未解决问题。请执行下列操作:

  1. Open a terminal

  2. Execute find /usr/lib/php/extensions -name "xdebug.so"to know the path to the debug library.

  3. Execute sudo nano /etc/php.inito open and edit the php.ini file
  4. In php.ini add the following lines at the end

    [XDebug]
    zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    
  1. 打开终端

  2. 执行find /usr/lib/php/extensions -name "xdebug.so"以了解调试库的路径。

  3. 执行sudo nano /etc/php.ini打开并编辑php.ini文件
  4. 在 php.ini 最后添加以下几行

    [XDebug]
    zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    

(When finished, type control+oto save and control+xto close the file)

(完成后,键入control+o以保存并control+x关闭文件)

(Don't forget to replace the value in zend_extension for whatever you got from the first terminal command)

(不要忘记将 zend_extension 中的值替换为您从第一个终端命令获得的任何值)

  1. Execute sudo apachectl restartto load the new configuration
  2. Sit back and relax
  1. 执行sudo apachectl restart加载新配置
  2. 高枕无忧

回答by tleo

I had to brew install xdebugand choose for my version of PHP and it worked! For example,

我不得不brew install xdebug为我的 PHP 版本选择,它奏效了!例如,

brew install homebrew/php/php56-xdebug

For a PHP version 5.6 variant.

对于 PHP 5.6 版本的变体。

回答by ltzMaxwell

For the issue phpize error,try this will solve your problem: sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include

对于问题 phpize 错误,试试这将解决您的问题: sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/包括

回答by greyfox

For anyone who is facing this issue I had to build autoconf from source. I followed this answer from another StackOverflow question.

对于遇到此问题的任何人,我都必须从源代码构建 autoconf。我从另一个 StackOverflow 问题中遵循了这个答案。

https://stackoverflow.com/a/12333230/2272004

https://stackoverflow.com/a/12333230/2272004