mac os 下php安裝mcrypt擴充套件

啟程發表於2014-11-29

MCrypt是一個功能強大的加密演算法擴充套件庫,它包括有22種演算法。
1:下載並解壓mcrypt-2.6.8.tar.bz2。(2.6.8為版本號,可以自行選擇,但是注意後邊步驟要與下載的版本號一致。)
2:在終端執行命令(注意如下命令需要安裝xcode支援):

cd ~/Downloads/mcrypt-2.5.8
./configure --disable-posix-threads --enable-static
make
sudo make install

3:下載並解壓php原始碼,根據自己情況選擇對應版本。(注意以下命令中php的版本)
在終端執行命令:(如果出錯請看後邊)

cd ~/Downloads/php-5.5.14/ext/mcrypt
phpize
./configure
make
cd modules
sudo cp mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20121212/

(cd modules後當出現

Build complete.
Don`t forget to run `make test`.

表示安裝成功。)

4:開啟php.ini

sudo vi /etc/php.ini

新增如下程式碼:(注意no-debug-non-zts-20121212版本號,如果不清楚可以前往/usr/lib/php/extensions/檢視)

extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/mcrypt.so

*如果phpize出現如下錯誤:

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

表示需要安裝autoconf

*如果make出現如下錯誤:

/ext/mcrypt/mcrypt.c:25:10: fatal error: `php.h` file not found

執行如下命令即可:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include /usr/include

*注意MacOSX10.10.sdk修改為自己系統的版本號*

相關文章