Mac Catalina安装Xdebug [英] Mac Catalina Install Xdebug

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

问题描述

我一直在努力让xdebug整天工作.我已经尝试过完全重新安装自制软件,清除了php并安装了最新版本,重新安装了apache(以下内容: https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions ),现在已经尝试使用pecl以及从xdebug和我的源代码进行安装继续出错.尝试通过pecl安装:

I've been struggling to get xdebug to work all day. 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. Trying to install via 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

或者从实际来源制作时,我会在make install上获得以下内容:

Or when making from the actual source i get the following on 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 % 

权限和Catalina中的只读文件系统一定有问题,我似乎无法全神贯注.我什至尝试关闭SIP.

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. I even tried turning off SIP.

有任何线索吗?

PHP,Apache,Homebrew,Eclipse均已安装并正常工作.无法使xdebug正常工作.

PHP, Apache, Homebrew, Eclipse are all installed and working..just can't get xdebug to work.

推荐答案

好,感谢德里克(Derek)的帮助,我的工作顺利了.这是我为完整的Mac PHP开发设置所做的:

Ok, I got this working, thanks to Derek's help. Here is what I did for a full Mac PHP Development setup:

0)如果尚未安装必备软件(自制软件,xcode等),请安装

0) Install prerequisite software if not already installed (homebrew, xcode, etc)

Xcode命令行工具:

Xcode command line tools:

$ xcode-select --install

自制软件:

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

Catalina必需的库:

Catalina Required Libraries:

 $ brew install openldap libiconv

1)完全卸载php,httpd(apache),并删除xdebug文件(如果已安装):

1) Completely uninstall php, httpd (apache), and delete xdebug files (if you had them already installed):

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

根据brew list命令查找已安装的php版本,然后将其卸载,例如:

Find whatever versions of php you have installed based on the brew list command then uninstall them, e.g.:

brew uninstall --force php72

清除所有旧的php配置

Clean out any old php configurations

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

2)安装Apache

2) Install Apache

如果您已经在运行内置的Apache,则需要先将其关闭,并删除所有自动加载脚本:

If you already have the built-in Apache running, it will need to be shutdown first, and any auto-loading scripts removed:

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

安装Apache:

$ brew install httpd

将Apache设置为自动启动:

Setup Apache to autostart:

$ sudo brew services start httpd

您现在应该可以转到 http://localhost:8080 并看到有效"消息

You should now be able to go to http://localhost:8080 and see an "It Works" message.

3)配置Apache

3) Configure Apache

使用您喜欢的文本编辑器,打开/usr/local/etc/httpd/httpd.conf

Using your favorite text editor, open /usr/local/etc/httpd/httpd.conf

找到显示Listen 8080的行并将其更改为Listen 80

Find the line that says Listen 8080 and change it to Listen 80

如果需要,请更改为服务网站的默认目录.搜索术语DocumentRoot,然后将值更改为所需的位置.我用过:

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. I used:

/Library/WebServer/Documents

,但您可以将其放置在任意位置(例如/Users/your_user/Sites)

but you can put it anywhere you like (such as /Users/your_user/Sites for example)

您还需要在DocumentRoot行下方更改标记参考.还应该将其更改为也指向您的新文档根目录:

You also need to change the tag reference right below the DocumentRoot line. This should also be changed to point to your new document root also:

 /Library/WebServer/Documents

在同一块中,您会找到一个AllowOverride设置,应将其更改为:

In that same block you will find an AllowOverride setting, this should be changed to:

# 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

此外,我们现在应该启用默认情况下已注释掉的mod_rewrite.搜索mod_rewrite.so并通过删除开头的#:

Also we should now enable mod_rewrite which is commented out by default. Search for mod_rewrite.so and uncomment the line by removing the leading #:

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

将服务器名称更改为localhost

保存文件.

重新启动Apache以确保您的更改生效:

Restart Apache to ensure your changes take effect:

$ sudo apachectl -k restart

3)安装PHP

我安装了php 7.2,即使它不是最新版本,也仅仅是因为我的托管站点和wordpress使用php 7.2,并且我想将我的php应用程序与wordpress站点集成在一起.

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.

$ brew install php@7.2

一旦安装了php,请返回您的httpd.conf文件并添加以下行:

Once php is installed, go back to your httpd.conf file and add the following line:

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

在先前未注释的LoadModule下面,从最后一步重写_module.

below the previously uncommented LoadModule rewrite _module from the last step.

还必须显式设置PHP的目录索引,因此搜索此块:

Also you must set the Directory Indexes for PHP explicitly, so search for this block:

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

复制并替换为:

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

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

保存文件,然后再次重新启动apache服务器:

Save the file and restart the apache server again:

$ sudo apachectl -k restart

4)验证php安装

只需在以前使用这种单线创建的Sites/文件夹中创建一个名为info.php的文件即可.

Simply create a file called info.php in your Sites/ folder you created earlier with this one-liner.

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

将浏览器指向 http://localhost/info.php ,您应该会看到一个PHP信息页面

Point your browser to http://localhost/info.php and you should see a PHP information page.

Homebrew应该在安装路径中将其首选的/usr/local/bin和/usr/local/sbin添加到您的路径中.通过键入以下内容进行快速测试:

Homebrew should have added its preferred /usr/local/bin and /usr/local/sbin to your path as part of its installation process. Quickly test this by typing:

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

如果看不到此内容,则可能需要将它们手动添加到路径中.根据您使用的shell,您可能需要将此行添加到〜/.profile,〜/.bash_profile或〜/.zshrc:

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:

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

5)安装Xdebug.

5) Install Xdebug.

如果命令:

$ pecl install xdebug

由于phpize无法返回正确的信息,或者由于它试图写入无法或无法找到php.h的文件夹而失败,就像它为我所做的和这篇文章的开始内容一样,请尝试以下操作:

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:

首先,您需要确保已安装Xcode和命令行工具.打开终端窗口,运行以下命令以显示SDK路径:

First, you need to make sure that Xcode and the command line tools installed. Open a terminal window and run the following command to display the SDK path:

$ xcrun --show-sdk-path

此命令应输出如下内容:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

This command should output something like this: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

如果没有安装,请使用步骤0中列出的命令进行安装.

If it doesn't, install them using the command listed in step 0.

现在在您的主文件夹中为phpize创建一个新文件夹:

Now create a new folder in your home folder for 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"

将该文件另存为phpize-catalina.patch在新的php-private文件夹中(请确保也将其插入该文件夹).

Save that file as phpize-catalina.patch in your new php-private folder (be sure to cd in to that folder too).

接下来修补新的phpize副本:

Next patch your new copy of phpize:

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

接下来,下载xdebug的最新源文件,对我来说是2.9.0

Next, download the latest source files of xdebug, for me it was 2.9.0

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

那应该已经将所有源文件下载到〜/xdebug路径.将目录更改为此路径.

That should have downloaded all the source files to the ~/xdebug path. Change directories to this path.

$ cd ~/xdebug

现在运行我们修补的phpize文件:

Now run the phpize file we patched:

$ ~/php-private/phpize

您应该看到以下输出:

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

如果收到错误:

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

这意味着您没有安装autoconf.试试:

It means you do not have autoconf installed. Try:

$ brew install autoconf

一旦收到以上phpize的输出,请配置并安装xdebug:

Once you receive the above output of phpize, configure and install xdebug:

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

这应该使用您在第3步中通过homebrew安装的php配置.

This should use the php config that you installed via homebrew in step 3.

现在构建扩展程序:

$ make

现在安装它:

$ 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.                                                            |
  |                                                                      |
  +----------------------------------------------------------------------+

现在,您需要将扩展​​名添加到php.ini文件中.使用您喜欢的编辑器修改/usr/local/etc/php/7.2/php.ini(打开文本编辑器时不要忘记sudo)并将其添加到最底端:

Now you need to add the extension to your php.ini file. 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:

[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

注意,您真正需要添加的只是zend_extension行,但是为了使其与Eclipse一起使用,我使用了启用远程标志以及此处列出的其他设置.

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.

最后,重新启动apache:

Finally, restart apache:

$ sudo apachectl -k restart

然后刷新先前创建的info.php页面时,您应该在配置中看到xdebug的行.像这样:

And then when you refresh the info.php page you created earlier you should see lines for xdebug in the configuration. Something like:

成功的xdebug验证

6)最后,对于我完整的PHP mac开发设置,我安装了最新版本的eclipse for php(来自他们的网站)以及SQL Server(使用自制软件).您可以在Google上搜索如何安装它们,因为它们非常简单.

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). You can google how to install those as they are pretty straightforward.

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

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