PHP安装Mcrypt扩展

来源:互联网 发布:安卓socket编程实例 编辑:程序博客网 时间:2024/04/30 23:20

       在使用PHP开发的过程中,为了提供数据传输的安全性,避免不了使用加密函数,除了使用php本身自带的几个函数,php还提供Mhash和Mcrypt2个扩展库。Mcrypt扩展库支撑的加密算法可以看http://mcrypt.sourceforge.net/,这里有对这个接口的详细介绍。

这里介绍2种安装Mcrypt扩展库的方法,算是对自己安装过程中遇到问题的一个总结。

1. 安装Mcrypt

      安装mcrypt的前提条件是安装 Libmcrypt 和 mhash 这2个库

libmcrypt(libmcrypt-2.5.8.tar.gz ):

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

       tar -zxvf libmcrypt-2.5.8.tar.gz
       #cd libmcrypt-2.5.8
       #./configure --prefix=$HOME/local/libmcrypt
       #make
       #make install

mhash(mhash-0.9.9.9.tar.gz ):

http://sourceforge.net/project/showfiles.php?group_id=4286&package_id=4300&release_id=645636

       #tar -zxvf mhash-0.9.9.9.tar.gz
       #cd mhash-0.9.9.9
       #./configure ----prefix=$HOME/local/mhash
       #make
       #make install    

       前面2个步骤安装都比较顺利。   

mcrypt(mcrypt-2.6.8.tar.gz ):

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

       在安装的mcrypt的过程中,如果遇到

       *** Could not run libmcrypt test program, checking why…
       *** The test program failed to compile or link. See the file config.log for the
       *** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
       *** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
       *** may want to edit the libmcrypt-config script: no
      configure: error: *** libmcrypt was not found

      正如前面所说的依赖关系,这个时候运行

      export path=$HOME/local/libmcrypt/binlibmcrypt_config

    这个步骤搞定,继续检查编译环境,又出现错误

     checking for mhash_keygen in -lmhash... no
     configure: error: "You need at least libmhash 0.8.15 to compile this program.http://mhash.sf.net/"

   export LD_LIBRARY_PATH=$HOME/local/libmcrypt/lib:$HOME/local/mhash/lib
   export LDFLAGS="-L$HOME/local/mhash/lib/ -I$HOME/local/mhash/include/"
   export CFLAGS="-I$HOME/local/mhash/include/"


    ./configure --prefix=$HOME/local/mcrypt/ --with-libmcrypt-prefix=$HOME/local/libmcrypt

     make & make install ,

到这来mcrypt安装完成,接下来就是给php添加扩展了。

2.安装php扩展

1.静态扩展

如果你还没有安装php,可以选择静态安装,静态安装的过程很简单,在./configure 后面添加 –with-mcrypt=dir 配置,完成。

2. 动态扩展

如果已经按照php,又不想重新编译php,则进行动态加载:进入php安装包,找到 ext/mcrypt,在这个目录下执行phpize,前提是phpize安装并且已经添加到环境变量中。之后,就得到configure文件。

     ./configure --with-php-config=/usr/local/php/bin/php-config --with-mcrypt=$HOME/local/libmcrypt
      make install 之后系统。mcrypt.so已经安装到默认目录中去了。

     修改php.ini中指示的extension_dir指向的目录中,将其复制过去。修改php.ini,在最后添加一句extension=mcrypt.so(注意别在最后添加一个空格,为这玩意,找了半小时),最后重启php和nginx服务。运行php -i|grep -i mcrypt查看是否安装成功。




0 0