mac 下安装 xdebug

环境:mac 电脑,php7.2.16

官网给出的安装方法是

pecl install xdebug

但提示没有 pecl
所以还得安装一下 pecl

cd src
curl -o go-pear.php https://pear.php.net/go-pear.phar  

这里的下载源码编译都统一放在 ~/src 下了
如果下载失败,一般是网址错误,下载下来的页面会告诉你正确的网址在哪里
这里我们运行下命令 sudo php go-pear.php
后面填入的内容是
1 回车 /usr/local/pear 回车
4 回车 /usr/local/bin 回车
回车

➜  src sudo php go-pear.php

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /usr/local
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/local/bin
 5. PHP code directory ($php_dir)                 : /usr/local/lib/php
 6. Documentation directory                       : /usr/local/docs
 7. Data directory                                : /usr/local/data
 8. User-modifiable configuration files directory : /usr/local/cfg
 9. Public Web Files directory                    : /usr/local/www
10. System manual pages directory                 : /usr/local/man
11. Tests directory                               : /usr/local/tests
12. Name of configuration file                    : /usr/local/etc/pear.conf

1-12, 'all' or Enter to continue: 1
(Use $prefix as a shortcut for '/usr/local', etc.)
Installation base ($prefix) [/usr/local] : /usr/local/pear

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /usr/local/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/local/pear/bin
 5. PHP code directory ($php_dir)                 : /usr/local/pear/lib/php
 6. Documentation directory                       : /usr/local/pear/docs
 7. Data directory                                : /usr/local/pear/data
 8. User-modifiable configuration files directory : /usr/local/pear/cfg
 9. Public Web Files directory                    : /usr/local/pear/www
10. System manual pages directory                 : /usr/local/pear/man
11. Tests directory                               : /usr/local/pear/tests
12. Name of configuration file                    : /usr/local/etc/pear.conf

1-12, 'all' or Enter to continue: 4
(Use $prefix as a shortcut for '/usr/local/pear', etc.)
Binaries directory [$prefix/bin] : /usr/local/bin

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /usr/local/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/local/bin
 5. PHP code directory ($php_dir)                 : /usr/local/pear/lib/php
 6. Documentation directory                       : /usr/local/pear/docs
 7. Data directory                                : /usr/local/pear/data
 8. User-modifiable configuration files directory : /usr/local/pear/cfg
 9. Public Web Files directory                    : /usr/local/pear/www
10. System manual pages directory                 : /usr/local/pear/man
11. Tests directory                               : /usr/local/pear/tests
12. Name of configuration file                    : /usr/local/etc/pear.conf

1-12, 'all' or Enter to continue:
Beginning install...
Configuration written to /usr/local/etc/pear.conf...
Initialized registry...
Preparing to install...
installing phar:///Users/apple/src/go-pear.php/PEAR/go-pear-tarballs/Archive_Tar-1.4.8.tar...
installing phar:///Users/apple/src/go-pear.php/PEAR/go-pear-tarballs/Console_Getopt-1.4.3.tar...
installing phar:///Users/apple/src/go-pear.php/PEAR/go-pear-tarballs/PEAR-1.10.10.tar...
installing phar:///Users/apple/src/go-pear.php/PEAR/go-pear-tarballs/Structures_Graph-1.1.1.tar...
installing phar:///Users/apple/src/go-pear.php/PEAR/go-pear-tarballs/XML_Util-1.4.3.tar...
install ok: channel://pear.php.net/Archive_Tar-1.4.8
install ok: channel://pear.php.net/Console_Getopt-1.4.3
install ok: channel://pear.php.net/Structures_Graph-1.1.1
install ok: channel://pear.php.net/XML_Util-1.4.3
install ok: channel://pear.php.net/PEAR-1.10.10
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"

The 'pear' command is now at your service at /usr/local/bin/pear

上面 pecl 就安装成功了
我们可以安装 xdebug 了

➜  src sudo pecl install xdebug
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.9.3.tgz ...
Starting to download xdebug-2.9.3.tgz (243,540 bytes)
..................................................done: 243,540 bytes
91 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
building in /private/tmp/pear/install/pear-build-rootAmGpCP/xdebug-2.9.3
running: /private/tmp/pear/install/xdebug/configure --with-php-config=/usr/local/bin/php-config

安装完成后,我们需要在 php.ini 中加入( 可通过 php -i|grep php.ini 命令来获取 php.ini 的路径)

vim /usr/local/lib/php.ini

[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_connect_back=0
xdebug.remote_host=0.0.0.0
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_enable_trigger_value=666
xdebug.profiler_output_dir=/Users/apple

重启 php

➜  src sudo killall php-fpm
➜  src sudo /usr/local/sbin/php-fpm

查看 phpinfo() 后,就可以看到 xdebug 了

你可能感兴趣的:(php,mac)