下载 libmcrypt 最新版本:libmcrypt-2.5.8.tar.gz
在终端执行以下命令,编译并安装它:
tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make sudo make install
在终端执行以下命令,查看当前 Mac OS X 系统当前默认安装的 PHP 版本:
php -v
得到的结果可能是这样的:
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
安装 Autoconf
Install
可以使用 brew
install
autoconf也可以使用如下命令
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
Mac OS X 10.10 Yosemite
在终端执行以下命令:
tar zxvf php-5.5.14.tar.gz cd php-5.5.14/ext/mcrypt phpize ./configure make sudo make install
安装完成后,执行以下命令,检查下 mcrypt 扩展是否能够正常加载:
php -m
如果遇上扩展编译版本和 PHP 编译版本不符的情况,会看到如下错误提示:
PHP Warning: PHP Startup: mcrypt: Unable to initialize module Module compiled with module API=20100525 PHP compiled with module API=20121212 These options need to match in Unknown on line 0
执行执行 phpize 报错:
1
2
3
4
5
6
7
|
grep
:
/usr/include/php/main/php
.h:
file
or
grep
:
/usr/include/php/Zend/zend_modules
.h:
file
or
grep
:
/usr/include/php/Zend/zend_extensions
.h:
file
or
Configuring
for
:
PHP
Zend
Zend
|
这个时候可能是因为 phpize 版本问题导致的,可以尝试解决办法::
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include /usr/include
或者:sudo
ln
-s
/Applications/Xcode
.app
/Contents/Developer/Platforms/MacOSX
.platform
/Developer/SDKs/MacOSX10
.9.sdk
/usr/include
/usr/include
cd php-5.5.14/ext/mcrypt phpize –-clean
接着再从头到位安装一遍,应该就没啥问题了。
完成 mcrypt php 扩拓展安装
cd ../php-5.5.9/ext/mcrypt/
/usr/bin/phpize
Output should be similar to:
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
./configure
make
sudo make install
The result of this should be similar to:
Installing shared extensions:
Enabling mcrypt.so php Extension
Open
extension=mcrypt.so
If there is no
sudo cp /etc/php.ini.default /etc/php.ini
And allow write capability
sudo chmod u+w/etc/php.ini
Then add the line as above in your favourite text editor:
sudo nano /etc/php.ini
or
sudo vi /etc/php.ini
and add in the line:
extension=mcrypt.so
Restart Apache
sudo apachectl restart