最近在研究建一个组件化的框架,之前的Xdebug都是在配置在vagrant虚拟器里面的,这导致我在本地使用PHPSTORM调试时无法使用。所以需要在本地也配置一个。本文章特地记录一下安装过程以及当中碰到的问题。
环境配置
- apache、php为系统安装
- 全局变量:php、phpize
- 环境目录:
- php.ini - /private/etc/php.ini
##### 安装Xdebug
1、安装过程
mkdir src #创建源码目录
cd src
wget https://xdebug.org/files/xdebug-2.6.0.tgz
tar zxvf xdebug-2.6.0.tgz
cd xdebug-2.6.0
phpize #执行这个告诉xdebug文件php-config文件在哪里
./configure --enable-xdebug #坑一
make
make isntall #坑二
2、碰到的坑
- 坑一
执行./configure --enable-xdebug
时报错:-bash: ./configure: No such file or directory
,是因为mac没有安装:autoconf,下面安装autoconf
bash
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
- 坑二
当编译完成后执行安装make isntall
时报错:
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20131226/
cp: /usr/lib/php/extensions/no-debug-non-zts-20131226/#INST@12567#: Operation not permitted
make: *** [install-modules] Error 1
原来是OSX 10.11 El Capitan(或更高)新添加了一个新的安全机制叫系统完整性保护System Integrity Protection (SIP),所以对于目录
/System
/sbin
/usr
不包含(/usr/local/)
仅仅供系统使用,其它用户或者程序无法直接使用,而我们的/usr/lib/php/extensions/刚好在受保护范围内
解决办法
所以解决方法就是禁掉SIP保护机制,步骤是:
重启系统
按住Command + R (重新亮屏之后就开始按,象征地按几秒再松开,出现苹果标志,ok)
菜单“实用工具” ==>> “终端” ==>> 输入csrutil disable;执行后会输出:Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
再次重启系统
禁止掉SIP后,就可以顺利的安装了,当然装完了以后你可以重新打开SIP,方法同上,只是命令是csrutil enable
##### 配置xdebug
在make install
完毕后,有个返回参数**Installing shared extensions **是一定要记住的,返回信息如下:
Installing shared extensions: /usr/local/Cellar/php56/5.6.32_8/lib/php/extensions/no-debug-non-zts-20131226/
+----------------------------------------------------------------------+
| |
| INSTALLATION INSTRUCTIONS |
| ========================= |
| |
| See http://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: http://xdebug.org/docs-settings.php |
| - A list of all functions: http://xdebug.org/docs-functions.php |
| - Profiling instructions: http://xdebug.org/docs-profiling2.php |
| - Remote debugging: http://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配置
sudo vim /private/etc/php.ini
#在末尾添加如下代码
[xdebug]
zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so #返回的参数Installing shared extensions加上文件名xdebug.so
xdebug.remote_enable = On
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "localhost" #IDE监听地址
xdebug.remote_port = 9000 #监听端口
xdebug.idekey = PHPSTROM #IDEkey
:wq!
之后重启apache
sudo apachectl restart
##### 配置phpstorm
修改配置一:Preferences -> Languages & Frameworks -> PHP -> Debug
[Xdebug]
Debug port:9000 #跟上面配置文件一致
其它默认
修改配置二:Preferences -> Languages & Frameworks -> PHP -> Debug -> DBGp Proxy
IDE key : PHPSTROM #跟上面配置一致
Host : localhost #跟上面配置一致
Port : 80 #服务端口
到这里所有配置全部完成!
暂时无法评论哦~
暂无评论