简体   繁体   English

Mac Catalina 安装 Xdebug

[英]Mac Catalina Install Xdebug

I've been struggling to get xdebug to work all day.我一整天都在努力让 xdebug 工作。 I have tried a complete reinstall of homebrew, cleared out php and installed the newest version, reinstalled apache (following: https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions ) and now have tried to install using pecl as well as from the source xdebug and I continue to get errors.我已经尝试完全重新安装自制软件,清除 php 并安装最新版本,重新安装 apache(如下: https : //getgrav.org/blog/macos-catalina-apache-multiple-php-versions ),现在尝试使用 pecl 以及从源 xdebug 安装,我继续收到错误。 Trying to install via pecl:尝试通过 pecl 安装:

sudo pecl install xdebug
Password:

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in Validator.php on line 1933

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /usr/local/pear/share/pear/PEAR/PackageFile/v2/Validator.php on line 1933
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user

robshpiel1@iPutz47 ~ % pecl config-get php_dir
/usr/lib/php/

robshpiel1@iPutz47 ~ % sudo chown robshpiel1 /usr/lib/php 
chown: /usr/lib/php: Read-only file system

robshpiel1@iPutz47 ~ % pecl config-set php_dir /usr/local/opt/php@7.2/
config-set succeeded

robshpiel1@iPutz47 ~ % sudo pecl install xdebug                       

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in Validator.php on line 1933

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /usr/local/pear/share/pear/PEAR/PackageFile/v2/Validator.php on line 1933
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.9.0.tgz ...
Starting to download xdebug-2.9.0.tgz (242,853 bytes)
..................................................done: 242,853 bytes

Fatal error: Cannot use result of built-in function in write context in /usr/local/pear/share/pear/Archive/Tar.php on line 639

Or when making from the actual source i get the following on make install:或者从实际来源制作时,我在 make install 上得到以下信息:

robshpiel1@iPutz47 xdebug % sudo make install
Password:
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20180731/
cp: /usr/lib/php/extensions/no-debug-non-zts-20180731/#INST@4741#: Read-only file system
make: *** [install-modules] Error 1
robshpiel1@iPutz47 xdebug % 

Something has to be wrong with permissions and the read only file system in Catalina and I can't seem to wrap my head around it. Catalina 中的权限和只读文件系统一定有问题,我似乎无法理解它。 I even tried turning off SIP.我什至尝试关闭 SIP。

Any clues?有什么线索吗?

PHP, Apache, Homebrew, Eclipse are all installed and working..just can't get xdebug to work. PHP、Apache、Homebrew、Eclipse 都已安装并运行。只是无法让 xdebug 运行。

Ok, I got this working, thanks to Derek's help.好的,感谢 Derek 的帮助,我完成了这项工作。 Here is what I did for a full Mac PHP Development setup:这是我为完整的 Mac PHP 开发设置所做的:

0) Install prerequisite software if not already installed (homebrew, xcode, etc) 0) 如果尚未安装,请安装必备软件(自制软件、xcode 等)

Xcode command line tools: Xcode 命令行工具:

$ xcode-select --install

Homebrew:家酿:

    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Catalina Required Libraries:

Catalina Required Libraries: Catalina 所需的库:

 $ brew install openldap libiconv

1) Completely uninstall php, httpd (apache), and delete xdebug files (if you had them already installed): 1) 完全卸载 php、httpd (apache),并删除 xdebug 文件(如果您已经安装了它们):

$ brew update
$ brew upgrade
$ brew cleanup
$ brew list | grep php

Find whatever versions of php you have installed based on the brew list command then uninstall them, eg:根据 brew list 命令查找您已安装的任何版本的 php,然后卸载它们,例如:

brew uninstall --force php72

Clean out any old php configurations清除所有旧的 php 配置

rm -Rf /usr/local/etc/php/*

2) Install Apache 2)安装阿帕奇

If you already have the built-in Apache running, it will need to be shutdown first, and any auto-loading scripts removed:如果您已经运行了内置 Apache,则需要先关闭它,并删除所有自动加载脚本:

$ sudo apachectl stop
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

Install apache:安装阿帕奇:

$ brew install httpd

Setup Apache to autostart:设置 Apache 自动启动:

$ sudo brew services start httpd

You should now be able to go to http://localhost:8080 and see an "It Works" message.您现在应该能够访问http://localhost:8080并看到“It Works”消息。

3) Configure Apache 3)配置Apache

Using your favorite text editor, open /usr/local/etc/httpd/httpd.conf使用您喜欢的文本编辑器,打开/usr/local/etc/httpd/httpd.conf

Find the line that says Listen 8080 and change it to Listen 80找到显示Listen 8080的行并将其更改为Listen 80

If you want, change to default directory of where you serve your websites from.如果需要,请更改为您提供网站的默认目录。 Search for the term DocumentRoot and change the value to where you want.搜索词DocumentRoot并将值更改为您想要的位置。 I used:我用了:

/Library/WebServer/Documents

but you can put it anywhere you like (such as /Users/your_user/Sites for example)但你可以把它放在你喜欢的任何地方(例如/Users/your_user/Sites

You also need to change the tag reference right below the DocumentRoot line.您还需要更改 DocumentRoot 行正下方的标记引用。 This should also be changed to point to your new document root also:这也应该更改为指向您的新文档根目录:

 /Library/WebServer/Documents

In that same block you will find an AllowOverride setting, this should be changed to:在同一个块中,您将找到一个 AllowOverride 设置,应将其更改为:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All

Also we should now enable mod_rewrite which is commented out by default.此外,我们现在应该启用默认情况下已注释掉的 mod_rewrite。 Search for mod_rewrite.so and uncomment the line by removing the leading #:搜索 mod_rewrite.so 并通过删除前导 # 来取消注释该行:

LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

Change the user and group to match your currently logged in user:更改用户和组以匹配您当前登录的用户:

User your_user
Group staff

Change the servername to localhost将服务器名称更改为localhost

Save the file.保存文件。

Restart Apache to ensure your changes take effect:重新启动 Apache 以确保您的更改生效:

$ sudo apachectl -k restart

3) Install PHP 3) 安装 PHP

I installed php 7.2, even though it's not the latest, simply because my hosting site and wordpress uses php 7.2 and I want to integrate my php application with my wordpress site.我安装了 php 7.2,尽管它不是最新的,只是因为我的托管站点和 wordpress 使用 php 7.2,我想将我的 php 应用程序与我的 wordpress 站点集成。

$ brew install php@7.2

Once php is installed, go back to your httpd.conf file and add the following line:安装 php 后,返回 httpd.conf 文件并添加以下行:

LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so

below the previously uncommented LoadModule rewrite _module from the last step.在之前未注释的 LoadModule 下方重写上一步中的 _module。

Also you must set the Directory Indexes for PHP explicitly, so search for this block:此外,您必须明确设置 PHP 的目录索引,因此搜索此块:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

Copy and replace it with this:复制并替换为:

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Save the file and restart the apache server again:保存文件并再次重启apache服务器:

$ sudo apachectl -k restart

4) Validate the php installation 4)验证php安装

Simply create a file called info.php in your Sites/ folder you created earlier with this one-liner.只需在您之前使用此单行创建的 Sites/ 文件夹中创建一个名为 info.php 的文件。

echo "<?php phpinfo();" > ~/Sites/info.php

Point your browser to http://localhost/info.php and you should see a PHP information page.将浏览器指向http://localhost/info.php ,您应该会看到一个 PHP 信息页面。

Homebrew should have added its preferred /usr/local/bin and /usr/local/sbin to your path as part of its installation process. Homebrew 应该在安装过程中将其首选的 /usr/local/bin 和 /usr/local/sbin 添加到您的路径中。 Quickly test this by typing:通过键入以下内容快速测试:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin

If you don't see this, you might need to add these manually to your path.如果您没有看到这一点,您可能需要手动将这些添加到您的路径中。 Depending on your shell you're using, you may need to add this line to ~/.profile, ~/.bash_profile, or ~/.zshrc:根据您使用的 shell,您可能需要将此行添加到 ~/.profile、~/.bash_profile 或 ~/.zshrc:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

5) Install Xdebug. 5) 安装 Xdebug。

If the command:如果命令:

$ pecl install xdebug

Fails due to the phpize not returning the correct information, or it's trying to write to folders it cannot, or it cannot find php.h, etc, as it did for me and what started this post, try the following:由于 phpize 没有返回正确的信息而失败,或者它试图写入它无法写入的文件夹,或者它找不到 php.h 等,就像它对我所做的那样以及这篇文章的开头,请尝试以下操作:

First, you need to make sure that Xcode and the command line tools installed.首先,您需要确保已安装 Xcode 和命令行工具。 Open a terminal window and run the following command to display the SDK path:打开终端窗口并运行以下命令以显示 SDK 路径:

$ xcrun --show-sdk-path

This command should output something like this: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk此命令应输出如下内容: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

If it doesn't, install them using the command listed in step 0.如果没有,请使用步骤 0 中列出的命令安装它们。

Now create a new folder in your home folder for phpize:现在在您的主文件夹中为 phpize 创建一个新文件夹:

$ mkdir ~/php-private/

And copy the following file to it:并将以下文件复制到其中:

$ cp /usr/bin/phpize ~/php-private/

Open a text editor, and create a file with the following patch code:打开文本编辑器,并使用以下补丁代码创建一个文件:

--- /usr/bin/phpize 2019-09-11 02:46:18.000000000 +0200
+++ ./phpize    2019-12-26 23:10:32.000000000 +0100
@@ -1,11 +1,12 @@
 #!/bin/sh

 # Variable declaration
+XCODE_SDK_ROOT=$(/usr/bin/xcrun --show-sdk-path)
 prefix='/usr'
 datarootdir='/usr/php'
 exec_prefix="`eval echo ${prefix}`"
 phpdir="`eval echo ${exec_prefix}/lib/php`/build"
-includedir="`eval echo ${prefix}/include`/php"
+includedir="`eval echo ${XCODE_SDK_ROOT}${prefix}/include`/php"
 builddir="`pwd`"
 SED="/usr/bin/sed"

Save that file as phpize-catalina.patch in your new php-private folder (be sure to cd in to that folder too).将该文件另存为 phpize-catalina.patch 在您的新 php-private 文件夹中(确保也将 cd 放入该文件夹)。

Next patch your new copy of phpize:接下来修补您的 phpize 新副本:

$ patch ~/php-private/phpize < phpize-catalina.patch    

Next, download the latest source files of xdebug, for me it was 2.9.0接下来下载xdebug的最新源文件,对我来说是2.9.0

$ git clone git://github.com/xdebug/xdebug.git

That should have downloaded all the source files to the ~/xdebug path.这应该已经将所有源文件下载到 ~/xdebug 路径。 Change directories to this path.将目录更改为此路径。

$ cd ~/xdebug

Now run the phpize file we patched:现在运行我们修补的 phpize 文件:

$ ~/php-private/phpize

You should see the following output:您应该看到以下输出:

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

If you receive the error:如果您收到错误:

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

It means you do not have autoconf installed.这意味着您没有安装 autoconf。 Try:尝试:

$ brew install autoconf

Once you receive the above output of phpize, configure and install xdebug:收到 phpize 的上述输出后,请配置并安装 xdebug:

./configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config

This should use the php config that you installed via homebrew in step 3.这应该使用您在第 3 步中通过自制软件安装的 php 配置。

Now build the extension:现在构建扩展:

$ make

Now install it:现在安装它:

$ make install

You should see something like:你应该看到类似的东西:

Installing shared extensions:     /usr/local/Cellar/php@7.2/7.2.26/pecl/20170718/

  +----------------------------------------------------------------------+
  |                                                                      |
  |   INSTALLATION INSTRUCTIONS                                          |
  |   =========================                                          |
  |                                                                      |
  |   See https://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:  https://xdebug.org/docs-settings.php    |
  |   - A list of all functions: https://xdebug.org/docs-functions.php   |
  |   - Profiling instructions:  https://xdebug.org/docs-profiling2.php  |
  |   - Remote debugging:        https://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.                                                            |
  |                                                                      |
  +----------------------------------------------------------------------+

Now you need to add the extension to your php.ini file.现在您需要将扩展​​添加到您的 php.ini 文件中。 Use your favorite editor to modify /usr/local/etc/php/7.2/php.ini (don't forget sudo when opening your text editor) and add this to the very bottom:使用您喜欢的编辑器修改/usr/local/etc/php/7.2/php.ini (打开文本编辑器时不要忘记 sudo)并将其添加到最底部:

[xdebug]
zend_extension=/usr/local/Cellar/php@7.2/7.2.26/pecl/20170718/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000

Note, all you really need to add is the zend_extension line but in order to have it work with Eclipse I use the remote enabled flags along with the other settings listed there.请注意,您真正需要添加的只是 zend_extension 行,但为了让它与 Eclipse 一起使用,我使用远程启用标志以及此处列出的其他设置。

Finally, restart apache:最后,重启apache:

$ sudo apachectl -k restart

And then when you refresh the info.php page you created earlier you should see lines for xdebug in the configuration.然后当您刷新之前创建的 info.php 页面时,您应该会在配置中看到 xdebug 的行。 Something like:就像是:

succesful xdebug validation成功的 xdebug 验证

6) Finally, for my complete PHP mac development setup, I installed the latest version of eclipse for php (from their website) as well as SQL Server (using homebrew). 6) 最后,对于我完整的 PHP mac 开发设置,我为 php(从他们的网站)以及 SQL Server(使用自制软件)安装了最新版本的 eclipse。 You can google how to install those as they are pretty straightforward.您可以谷歌搜索如何安装它们,因为它们非常简单。

Each error has a different cause.每个错误都有不同的原因。

First of all, your sudo pecl install is generally the right way of installing Xdebug, because, as you've found you can set the installation directory with pecl config-set .首先,您的sudo pecl install通常是安装 Xdebug 的正确方法,因为正如您发现的,您可以使用pecl config-set安装目录。

However, the pecl/pear version that you are running, is likely for an old version of PHP.但是,您正在运行的 pecl/pear 版本可能适用于版本的 PHP。 Because PHP does change once in a while, the pecl tool needs to be updated too.因为 PHP 会不时发生变化,所以 pecl 工具也需要更新。 For PHP 7.2, I run pecl version 1.10.9 (you can check with pecl -V ).对于 PHP 7.2,我运行 pecl 版本 1.10.9(您可以使用pecl -V检查)。 I would think that the one you're running is quite a bit older.我认为你正在运行的那个是相当老的。 Generally you can update pear/pecl by using pear upgrade pear , but you will likely run into an unwritable directory problem again.通常您可以使用pear upgrade pear更新 pear/pecl ,但您可能会再次遇到无法写入的目录问题。

Secondly, sudo make install to fails because it is trying to write into an unwritable directory ( /usr/lib/php/extensions/no-debug-non-zts-20180731/ ).其次, sudo make install失败,因为它试图写入不可写的目录( /usr/lib/php/extensions/no-debug-non-zts-20180731/ )。 If you know what the right directory is (check with php -i | grep extensions ), you can just copy it into that directory yourself.如果您知道正确的目录是什么(检查php -i | grep extensions ),您可以自己将其复制到该目录中。 After the make stage, there should be a xdebug.so in the modules directory within the Xdebug source tree.make阶段之后,Xdebug 源代码树中的modules目录中应该有一个xdebug.so

The "official" way to solve the latter problem is to use the --with-php-config option to Xdebug's ./configure line, where you can specify the one that you want to use for Xdebug with something like: ./configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config (but check the paths, as I don't have a Mac set up here).解决后一个问题的“官方”方法是在 Xdebug 的./configure行中使用--with-php-config选项,您可以在其中指定要用于 Xdebug 的选项,例如: ./configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config (但请检查路径,因为我这里没有设置 Mac)。 This should then pick up the right extensions directory, and sudo make install should work.然后这应该选择正确的扩展目录,并且sudo make install应该可以工作。

请注意,如果您想在 MacOS 上本地安装 Xdebug,而无需 Homebrew,则可以遵循此答案

Alternatively, if you are a MAC user is to install MAMP.或者,如果您是 MAC 用户,则安装 MAMP。 It comes with the xdebug extension ready to use in all the versions of php that MAMP has built-in.它带有 xdebug 扩展,可以在 MAMP 内置的所有 php 版本中使用。

After installing MAMP, you just have to add these lines in the php.ini file corresponding to each version of PHP:安装 MAMP 后,您只需要在对应于每个 PHP 版本的php.ini文件中添加这些行:

For php8:对于 php8:

[xdebug]

zend_extension="/Applications/MAMP/bin/php/php8.0.0/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host=localhost
xdebug.remote_port=9003
xdebug.idekey="netbeans-xdebug"  // only for netbeans

for php 7.4 and earlier:对于 php 7.4 及更早版本:

[xdebug]

zend_extension="/Applications/MAMP/bin/php/php7.4.12/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.client_port=localhost
xdebug.remote_port=9003
xdebug.idekey="netbeans-xdebug"  // only for netbeans

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM