CentOS6.5 安装php(5.3.3)扩展 mcrypt

2023-05-06,,

 安装php

 1.yum -y install php php-fpm

(1)、确认你的linux没有安装mcrypt库,如果已安装,跳过安装步骤

# yum list installed|grep mcrypt

libmcrypt.x86_64        2.5.8-9.el6     @epel                                   

libmcrypt-devel.x86_64  2.5.8-9.el6     @epel                                   

mcrypt.x86_64           2.6.8-10.el6    @epel    


以上显示已经安装过,若没有,则按以下两种方式安装

(方法一)yum命令懒人安装

yum install libmcrypt libmcrypt-devel mcrypt mhash

执行后会显示即将安装的相关库,你可以根据你的linux限定x86_64或者i386,如yum install libmcrypt.x86_64(如果yum命令无法连接仓库,请检查你的/etc/yum.repos.d/里的文件正确性,以及你的/etc/host是不是可达里面的域名)

(方法二)源码编译安装,去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 ):
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文件夹

# cd php-5.3.3/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:         20090626Zend Module Api No:      20090626Zend Extension Api No:   220090626

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

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

# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
# ./configure --with-php-config=/usr/bin/php-config

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

# make && make install

最后的最后,会提示你如下,说明你大功告成了

Installing shared extensions:     /usr/lib64/php/modules/

顺便检查下/usr/lib64/php/modules/里的mrcypt.so扩展是否已经创建成功

然后的事就简单了,添加扩展。

方法一、给你的php.ini添加一条extension=mcrypt.so

方法二、创建一个mrcypt.ini文件就行,里面写extension=mcrypt.so

# cd /etc/php.d
# echo 'extension=mcrypt.so' > mcrypt.ini

最后检查是否添加扩展成功

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

# /etc/init.d/php-fpm restart

Stopping php-fpm:                                          [  OK  ]

Starting php-fpm:    


在你的php发布目录创建 php文件

# cat /home/default/ganinfo/index2.php 

<?php phpinfo(); ?>

 访问http://ip/index2.php,会看到自己php的配置

参考链接:http://www.cnblogs.com/huangzhen/archive/2012/09/12/2681861.html

《CentOS6.5 安装php(5.3.3)扩展 mcrypt.doc》

下载本文的Word格式文档,以方便收藏与打印。