CentOS下安装php mcrypt扩展的方法分享
时间:2015-04-06 17:04 来源:linux.it.net.cn 作者:IT
在centos中安装php的mcrypt扩展,大致分为如下的几个步骤:
1,安装mcrypt
2,安装php对mcrypt的扩展
3,重启apache,使扩展生效
首先,确认linux没有安装mcrypt库,已安装的话,跳过此步即可。
[root@test-206 ~]# yum list installed|grep mcrypt
libmcrypt.x86_64 2.5.8-4.el5.centos installed
libmcrypt-devel.x86_64 2.5.8-4.el5.centos installed
mcrypt.x86_64 2.6.8-1.el5 installed
以上显示已安装过。
未安装的,参考如下步骤安装。
方法1,yum方式安装
# yum install libmcrypt libmcrypt-devel mcrypt mhash
执行后会显示即将安装的相关库。
可以根据linux限定x86_64或i386,如:yum install libmcrypt.x86_64(如果yum命令无法连接仓库,请检查/etc/yum.repos.d/中文件的正确性,以及/etc/host是不是可达其中的域名)
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
libmcrypt i386 2.5.7-5.el5 epel 124 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libmcrypt-devel i386 2.5.7-5.el5 epel 103 k
libmcrypt-devel x86_64 2.5.8-4.el5.centos extras 10 k
mcrypt x86_64 2.6.8-1.el5 epel 88 k
mhash i386 0.9.2-6.el5 epel 141 k
mhash x86_64 0.9.9-1.el5.rf rpmforge 161 k
Transaction Summary
================================================================================
Install 7 Package(s)
Upgrade 0 Package(s)
Total download size: 731 k
Is this ok [y/N]:
确定安装,最后显示
Installed:
libmcrypt.x86_64 0:2.5.8-4.el5.centos
libmcrypt-devel.x86_64 0:2.5.8-4.el5.centos
mcrypt.x86_64 0:2.6.8-1.el5
mhash.x86_64 0:0.9.9-1.el5.rf
Complete!
方法2,源码编译安装。
下载地址:http://www.sourceforge.net
1,下载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 ):
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
#make
#make install
2)、安装php的mcrypt扩展(动态加载编译)
下载php下的mcrypt扩展或直接下载php的完整安装包:
http://cn.php.net/releases/ 找到自己服务器的php版本,下载后tar解压(这里是php5.3.3)
进入ext/mcrypt文件夹:
[root@jbxue 14:45 ~]# cd php-5.3.3/ext/mcrypt/
执行phpize命令(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,如果没有?yum install php53-devel中有)
[root@jbxue 14:48 mcrypt]# whereis phpize //为了确定phpize存在
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz
[root@jbxue 14:48 mcrypt]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
执行后,当前目录下多了一些configure文件,最后执行php-config命令。
执行以下命令,确保/usr/bin/php-config是存在的:
[root@jbxue 15:02 mcrypt]# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
[root@jbxue 15:02 mcrypt]# ./configure --with-php-config=/usr/bin/php-config
如果出现如下的错误:
configure: error: no acceptable C compiler found in $PATH
请先安装gcc,执行命令:
复制代码代码示例:
yum install gcc
直到不报错,出现:config.status: creating config.h,执行以下命令:
复制代码代码示例:
[root@jbxue 15:06 mcrypt]# make && make install
出现提示:
Installing shared extensions: /usr/lib64/php/modules/
检查下/usr/lib64/php/modules/中mrcypt.so扩展是否成功创建。
接下来,在php.ini文件中添加:
extension=mcrypt.so
[root@jbxue 15:09 mcrypt]# cd /etc/php.d
创建一个mrcypt.ini文件就行,其中写入:
复制代码代码示例:
extension=mcrypt.so
[root@jbxue 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
3)、重启apache,查阅phpinfo文件。
出现如下图所示的内容,则mcrypt模块扩展已正确安装并加载。

(责任编辑:IT)
在centos中安装php的mcrypt扩展,大致分为如下的几个步骤:
首先,确认linux没有安装mcrypt库,已安装的话,跳过此步即可。
[root@test-206 ~]# yum list installed|grep mcrypt
libmcrypt.x86_64 2.5.8-4.el5.centos installed libmcrypt-devel.x86_64 2.5.8-4.el5.centos installed mcrypt.x86_64 2.6.8-1.el5 installed 以上显示已安装过。 未安装的,参考如下步骤安装。
方法1,yum方式安装
# yum install libmcrypt libmcrypt-devel mcrypt mhash
执行后会显示即将安装的相关库。
可以根据linux限定x86_64或i386,如:yum install libmcrypt.x86_64(如果yum命令无法连接仓库,请检查/etc/yum.repos.d/中文件的正确性,以及/etc/host是不是可达其中的域名)
Dependencies Resolved
Transaction Summary
Total download size: 731 k
确定安装,最后显示
Installed: Complete! 方法2,源码编译安装。
下载地址:http://www.sourceforge.net
libmcrypt(libmcrypt-2.5.8.tar.gz ):
mcrypt(mcrypt-2.6.8.tar.gz ): 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
复制代码代码示例:
#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 #make #make install
2)、安装php的mcrypt扩展(动态加载编译)
进入ext/mcrypt文件夹:
[root@jbxue 14:45 ~]# cd php-5.3.3/ext/mcrypt/
执行phpize命令(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,如果没有?yum install php53-devel中有)
[root@jbxue 14:48 mcrypt]# whereis phpize //为了确定phpize存在
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz [root@jbxue 14:48 mcrypt]# phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 执行后,当前目录下多了一些configure文件,最后执行php-config命令。
执行以下命令,确保/usr/bin/php-config是存在的:
[root@jbxue 15:02 mcrypt]# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz [root@jbxue 15:02 mcrypt]# ./configure --with-php-config=/usr/bin/php-config
如果出现如下的错误:
复制代码代码示例:
yum install gcc
直到不报错,出现:config.status: creating config.h,执行以下命令:
复制代码代码示例:
[root@jbxue 15:06 mcrypt]# make && make install
出现提示:
接下来,在php.ini文件中添加:
extension=mcrypt.so
[root@jbxue 15:09 mcrypt]# cd /etc/php.d
复制代码代码示例:
extension=mcrypt.so
[root@jbxue 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
3)、重启apache,查阅phpinfo文件。 (责任编辑:IT) |