Linux下解决php扩展模块mcrypt的问题

  本文记录并更正了一些流传甚广的网文在解决此问题时的不足与错漏之处。供以后参考。

  Ubuntu上出现此类问题,安装php5-mcrypt包即可

$ sudo apt-get install php5-mcrypt 

  安装完成后重启apache

$ sudo /etc/init.d/apache2 restart

 

  以下着重介绍在Redhat上的解决方案。

  当在编译php源码时忘记加入对mcrypt的扩展支持,就会出现此错误。该错误不大不小,但解决起来却很头疼。最直接的方法就是重新编译源码,然而直接却并不代表简单,简单也不能代表优雅。“在任何情况下都重装系统”也毕竟不是长久之计,久而久之,反而有可能会降低自己解决问题的能力。

   网上有资料显示,解决此问题需要三个包。

  libmcrypt-2.5.8.tar.gz   

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

  mhash-0.9.9.tar.gz

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

  mcrypt-2.6.8.tar.gz

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

注意:

  1. 先安装libmcrypt和mhash,两者之间没有依赖关系。而mcrypt需要依赖二者。

  2. 在解压mcrypt后,configure时,需要指定libmcrypt和mhash的安装目录。流传的网文在此步骤上多少都有点不完整。不过在configure失败时,只需要认真的阅读configure失败提示,以及使用./configure --help命令就可解决问题。例如下面错误信息:

checking for libmcrypt-config... no
checking for libmcrypt - version >= 2.5.0... no
*** 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: noconfigure: error: 
*** libmcrypt was not found

  错误提示没有找到libmcrypt-config文件,估计是没有找到libmcrypt安装目录。由于之前我们已经明确安装了,因此肯定是在configure时需要指定参数。通过./configure --help查看以及多方试探,最终确定参数如下。

# LD_LIBRARY_PATH=A:B ./configure --with-libmcrypt-prefix=C
A:  libmcrypt的lib目录,会解析成"A/lib"
B:  mhash的lib目录,会解析成"B/lib"
C: libmcrypt的安装目录,会解析成"C/bin/libmcrypt-config"。注意C最后不要加反斜杠"/"

  如果自己在安装libmcrypt和mhash时,指定了--prefix,则bin,include,share以及lib目录都会放置到自己指定的目录下。如果没有指定,默认情况下,bin目录下的文件放到 /usr/local/bin下,lib目录下的文件放置到/usr/local/lib下,bin同理放到/usr/local/bin下。

以我的Redhat5.x为例:libmcrypt安装到/usr/local/libmcrypt目录下,而mhash是默认安装的。

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

  三个文件都顺利安装之后,需要生成mcrypt.so扩展包。步骤如下:

  1、首先要先进入php的解压目录,进入ext/mcrypt这个目录。

  2、运行phpize,这个是负责调用外部安装相关操作的。

 

#  cd /home/install/php-5.2.6/ext/mcrypt
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config 和一些其他参数,具体是什么,我也忘记了。可以根据上文提到的办法解决。即认真看失败记录,以及--hellp选项。
#make
#make install

 

  最后把这个mcrypt.so文件直接扔到php的extensions目录下,然后和在php.ini中加上这项extensions。

posted on 2010-10-20 18:57  joolu  阅读(5242)  评论(0编辑  收藏  举报