基本原理是:首先使mcrypt软件能够运行,然后安装php扩展模块,并在php.ini配置。
这里注意的是mcrypt软件依赖libmcrypt和mhash两个库,所以安装配置顺序从右至左 I 下载安装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 ./configure
----------------------------------------------
报错:
*** Could not run libmcrypt test program, checking why…
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you’ll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it,> *** you may also be able to get things to work by modifying LD_LIBRARY_PATH
***configure: error: *** libmcrypt was not found
--------------
解决方法:
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH ./configure
---------------------------------------------
#make
#make install
说明:由于在配置Mcrypt时,会找不到libmcrypt的链接库,导致无法编译,因为Libmcrypt的链接库在/usr/local/文件夹下。因些在配置mcrypt时要加入LD_LIBRARY_PATH=/usr/local导入键接库 II. 安装PHP扩展模块
接着就要为PHP添加mcrypt模块了
1. 静态编译
在任意PHP文件中加入函数 phpinfo(),即可取得目前PHP的配置
在这些配置后面新增需要加入的配置:’–with-mcrypt=/usr/local/include’
然后进入php源代码目录,执行这条完整的configure命令
配置完成,下面进行源码包的制作和安装
make clean (一定需要)
make
make install
2. 动态加载
使用php的常见问题是:编译php时忘记添加某扩展,后来想添加扩展,但是因为安装php后又装了一些东西如PEAR等,不想删除目录重装,于是可以采用phpize。方法是: 要有与现有php完全相同的php压缩包。我用的是php-5.2.6.tar.gz。 展开后进入里面的ext/mcrypt目录(里面是mcrypt的php扩展),然后执行/usr/local/php/bin/phpize。phpize是安装php时安装好的一个工具,如果你的机器没有安装phpize工具,那么可能还是要make,make install php,仅仅为了得到phpize.
执行完后,会发现当前目录下多了一些configure文件, 如果没报错,则根据提示运行
./configure --with-php-config=/usr/local/php/bin/php-config
注意要先确保/usr/local/php/bin/php-config存在。
make
make install
Php代码:./configure --with-php-config=/usr/local/php/bin/php-config make install 之后系统会提示你mcrypt.so文件所在的目录。
在php.ini中添加extension_dir指向的目录(上述make install后出现的目录), 将其复制过去。并添加extension=mcrypt.so
最后重启APACHE服务,万事OK。