YiluPHP
这家伙很懒,什么都没有留下...

经验 CentOS下php安装mcrypt扩展

浏览数 181839
本方法在本人测试环境下安装成功,Linux版本centos6.9,php5.6.31

1. 源码编译安装,去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包
libmcrypt(libmcrypt-2.5.8.tar.gz )
mcrypt(mcrypt-2.6.8.tar.gz )
mhash(mhash-0.9.9.9.tar.gz )

#cd /software
#wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
#wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
#wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz

2 .先安装Libmcrypt

#tar -zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make && make install 说明:libmcript默认安装在/usr/local

3.安装mhash
#cd /software
#tar -zxvf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure
#make && make install

4.安装mcrypt
#cd /software
#tar -zxvf mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8
#LD_LIBRARY_PATH=/usr/local/lib ./configure
#make && make install

安装php的mcrypt扩展(动态加载编译)

下载php下的mcrypt扩展或者直接下载php的完整安装包
http://www.php.net/releases/ 网页下找到自己服务器的php版本,下载后tar解压(本人已经安装好了php5.6.31,源码包还在,所以直接进入/software/php-5.6.31/ext/mcrypt/使用就好了)
进入ext/mcrypt目录

执行phpize命令(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,如果没有?yum install php53-devel里包含了,或者其他方法)

[root@*_* 14:48 mcrypt]# whereis phpize //为了确定phpize存在
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz
[root@*_* 14:48 mcrypt]# phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226

执行完后,会发现当前目录下多了一些configure文件,最后执行php-config命令就基本完成了

执行以下命令,确保你的/usr/bin/php-config是存在的

[root@*_* 15:02 mcrypt]# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz

[root@*_* 15:02 mcrypt]# ./configure --with-php-config=/usr/local/php/bin/php-config

如果遇到以下错误,请先安装gcc,命令yum install gcc

configure: error: no acceptable C compiler found in $PATH

直到不报错,出现:config.status: creating config.h,执行以下命令

[root@*_* 15:06 mcrypt]# make && make install

最后的最后,会提示你如下,说明你大功告成了
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

然后的事就简单了,给你的php.ini添加一条extension=mcrypt.so

vim /usr/local/php/lib/php.ini

重启php,查阅phpinfo,mcrypt模块扩展是不是加载了?
service php-fpm restart

或者在命令行下查看php的扩展
#php -m | grep mcrypt

mcrypt

#php -i | grep mcrypt

Registered Stream Filters => zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
PWD => /software/php-5.6.31/ext/mcrypt
_SERVER["PWD"] => /software/php-5.6.31/ext/mcrypt



我来说说