Home  >  Article  >  php教程  >  OS X EI Capitan安装mcrypt,capitanmcrypt

OS X EI Capitan安装mcrypt,capitanmcrypt

WBOY
WBOYOriginal
2016-06-13 08:48:43893browse

OS X EI Capitan安装mcrypt,capitanmcrypt

OS X EI Capitan安装mcrypt   (我的博客原文:http://www.jmolboy.com/2015/12/01/mcrypt-extension-on-EI-Capitan/)   12月 01, 2015 发布在 php扩展

mac操作系统升级到10.11.2(OS X EI Capitan)后,系统自带的php也被修改覆盖了;之前安装的php扩展全无法继续使用了;而mcrypt扩展急需使用,可是怎么安装都无法安装成功;困扰了好久。编译后执行安装时总是提示

<span class="line">1</span>
<span class="line">[cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST@17000#: Operation not permitted]</span>

终于找到了问题所在

什么鬼

当你进入/usr/lib/php/extensions/目录时你会发现目录根本无法操作(手动拷贝、移动),使用root在终端也没有权限;可是不可能啊?我已经是root用户了,为什么还不允许;原来是OSX 10.11 El Capitan新添加了一个新的安全机制叫系统完整性保护System Integrity Protection (SIP),所以对于目录

  • /System
  • /sbin
  • /usr
  • 不包含(/usr/local/)

仅仅供系统使用,其它用户或者程序无法直接使用,而我们的/usr/lib/php/extensions/刚好在受保护范围内

禁SIP

所以解决方法就是禁掉SIP保护机制,步骤是:

  • 重启系统
  • 按住Command + R
  • 菜单“实用工具” ==>> “终端” ==>> 输入csrutil disable;执行后会输出:Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
  • 再次重启系统

禁止掉SIP后,就可以顺利的安装了,当然装完了以后你可以重新打开SIP,方法同上,只是命令是csrutil enable

完整安装

<span class="line">1</span>
<span class="line">cd ~ ; mkdir mcrypt ; cd mcrypt</span>

分别下载
libmcrypt2.5.8、你系统的php版本到mcrypt目录

解压

<span class="line">1</span>
<span class="line">tar -zxvf libmcrypt-2.5.8.tar.gz
tar -zxvf php-5.5.27.tar.gz
rm *.gz</span>

安装libmcrypt

<span class="line">1</span>
<span class="line">cd libmcrypt-2.5.8
./configure
make
sudo make install</span>

安装autoconf

<span class="line">1</span>
<span class="line">cd ~/mcrypt
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xvfz autoconf-latest.tar.gz
cd autoconf-2.69/
./configure
make
sudo make install</span>

编译mcrypt的php扩展

<span class="line">1</span>
<span class="line">cd ../php-5.5.27/ext/mcrypt/
/usr/bin/phpize</span>

上面会输出:

<span class="line">1</span>
<span class="line">Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212</span>

接着编译:

<span class="line">1</span>
<span class="line">./configure
make
sudo make install</span>

上面会输出:

<span class="line">1</span>
<span class="line">Installing shared extensions:  /usr/lib/php/extensions/no-debug-non-zts-20121212/</span>

如果出现错误(我遇到的):

<span class="line">1</span>
<span class="line">cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST@17000#: Operation not permitted</span>

就说明你需要先禁掉SIP(如何禁掉SIP见上面)

修改/etc/php.ini,增加扩展extension=mcrypt.so

再重启apache

<span class="line">1</span>
<span class="line">sudo apachectl restart</span>

再看你的phpinfo();就会出现mcrypt信息了;

(我的博客原文:http://www.jmolboy.com/2015/12/01/mcrypt-extension-on-EI-Capitan/)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn