整理 mac 安装php扩展mcrypt


这个问题是遇到多次了,不想再被坑了,

首先使mcrypt软件能够运行,然后安装php扩展模块,并在php.ini配置。

 这里注意的是mcrypt软件依赖libmcrypt和mhash两个库,所以安装配置顺序从右至左

下载安装mcrypt

1.先去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包 ,下面是我找到的链接

Libmcrypt(libmcrypt-2.5.8.tar.gz ):

http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459

mcrypt(mcrypt-2.6.8.tar.gz ):

http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91948&release_id=642101


mhash(mhash-0.9.9.9.tar.gz ):
http://sourceforge.net/project/showfiles.php?group_id=4286&package_id=4300&release_id=645636

 2 .先安装Libmcrypt

   #tar -zxvf libmcrypt-2.5.8.tar.gz

   #cd libmcrypt-2.5.8

   #./configure

   #make

   #make install

   说明:libmcript默认安装在/usr/local 


3.安装mhash

   #tar -zxvf mhash-0.9.9.9.tar.gz

   #cd mhash-0.9.9.9

   #./configure

   #make

   #make install


4.安装mcrypt

   #tar -zxvf mcrypt-2.6.8.tar.gz

   #cd mcrypt-2.6.8

   #LD_LIBRARY_PATH=/usr/local/lib/ ./configure -with-libmcrypt-prefix=/usr/local

   #make

   #make install

   说明:由于在配置Mcrypt时,会找不到libmcrypt的链接库,导致无法编译,因为Libmcrypt的链接库在/usr/local/文件夹下。因些在配置mcrypt时要加入LD_LIBRARY_PATH=/usr/local导入键接库,

mac上有时会在make时有错误:rfc2440.c:26:20: error: malloc.h: No such file or directory,修改 rfc2440.c:#include #include , 重新make/make install即可,如在MAC10.9系统上有问题mcrypt fatal error: 'php.h' file not found,后面有详述

5.生成mcypt.so文件

  • 下载并解压PHP源码文件php-5.3.4.tar.gz(一定是和系统的php的版本号一致)。Mac OS X 10.6.3中预装的PHP版本是5.3.4,所以需要下载这个版本。
  • 在终端执行如下命令:
    tar zxvf php-5.3.4.tar.gz
    cd php-5.3.4/ext/mcrypt
    phpize(如果./configure不能执行 先下载autoconf.tar.gz解压 在autoconf文件夹目录下执行./configure 然后make && make install  安装autoconf后就能在php文件夹下使用./configure配置php了 ,如这个装不上,后面还有详述
    ./configure
    make
    sudo cp modules/mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

  • 打开php.ini
    sudo vi /etc/php.ini

    usr/etc/php.ini,中加入如下代码,并保存后退出,然后重启Apache(如没有复制php.ini.default,有时要修改写权限:chmod  777 php.ini )
    extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
    到这就结束了。

    注意:mac系统升级到10.9(mavericks)时安装php扩展问题解决

    在装mcrypt插件时报错,提示:mcrypt fatal error: 'php.h' file not found,

    然后又仔细操作了一次在输完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: 

    解决办法:

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


    如autoconf安装不上,参考:
    http://www.mattvsworld.com/blog/2010/02/install-the-latest-autoconf-and-automake-on-mac-os-10-6/
    安装这4个:

    1.curl -O http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
    tar -xzvf m4-1.4.13.tar.gz
    cd m4-1.4.13
    ./configure --prefix=/usr/local
    make
    sudo make install
    cd ..

    2.curl -O http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
    tar -xzvf autoconf-2.65.tar.gz
    cd autoconf-2.65
    ./configure --prefix=/usr/local # ironic, isn't it?
    make
    sudo make install
    cd ..
    # here you might want to restart your terminal session, to ensure the new autoconf is picked up and used in the rest of the script

    3.curl -O http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
    tar xzvf automake-1.11.tar.gz
    cd automake-1.11
    ./configure --prefix=/usr/local
    make
    sudo make install
    cd ..

    4.curl -O http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
    tar xzvf libtool-2.2.6b.tar.gz
    cd libtool-2.2.6b
    ./configure --prefix=/usr/local
    make
    sudo make install



你可能感兴趣的:(ios)