Linux下php安装mcrypt扩展

PHP安全处理之Mcrypt使用总结:

我们知道在编写代码程序时,除了要保证代码的高性能,还有一个非常重要的,就是数据的安全。对于php而言,它本身提供了几种加密数据的办法,不过还是有限,对于满足特殊数据加解密方面有些欠缺,所以这里推荐使用的第三方拓展mcrypt库,它提供了类型、算法及模式繁多的加解密功能,那么下面来介绍下它的使用。

说明:

操作系统:CentOS 5.x 64位

已安装php版本:php-5.4.4

已安装php路径:/usr/local/php

实现目的:

在不影响网站访问的情况下,重新编译php,增加对mcrypt扩展的支持

具体操作:

一、下载软件包

1、下载php(版本要与系统安装的一致)

http://museum.php.net/php5/php-5.4.4.tar.gz

2、下载libmcrypt(安装mcrypt需要此软件包)

http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

3、下载mhash(安装mcrypt需要此软件包)

https://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz

4、下载mcrypt

https://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gz

以上软件包下载之后,上传到/usr/local/src目录

二、安装软件包

1、安装libmcrypt

cd /usr/local/src  #进入软件包存放目录

tar zxvf libmcrypt-2.5.8.tar.gz  #解压

cd libmcrypt-2.5.8  #进入安装目录

./configure  #配置

make  #编译

make install  #安装

2、安装mhash

cd /usr/local/src

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure

make

make install

3、安装mcrypt

cd /usr/local/src

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.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

三、重新编译php

1、查看系统之前安装的php编译参数

系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容 版权所有,转载请注明出处及原文链接

/usr/local/php/bin/php -i |grep configure #查看php编译参数,记录下编译参数,后面会用到

2、安装php

cd /usr/local/src

tar zxvf php-5.4.4.tar.gz

cd php-5.4.4

‘./configure’ ‘–prefix=/usr/local/php’ ‘–enable-mbstring=all’ ‘–with-config-file-path=/usr/local/php/etc’ ‘–with-zlib’ ‘–with-mysql=/usr/local/mysql-5.1.38/’ ‘–with-gd’ ‘–with-mysqli=/usr/local/mysql-5.1.38/bin/mysql_config’ ‘–with-jpeg-dir=/usr’ ‘–with-png-dir=/usr’ ‘–enable-fpm’ ‘–enable-soap’ ‘–with-freetype-dir=/usr/lib64’ ‘–with-iconv=/usr/local’ ‘–with-curl’ ‘–with-mcrypt’

#在之前的编译参数后面增加’–with-mcrypt’ 回车

make  #编译

make install  #安装

/usr/local/src/php-5.4.4/sapi/fpm/init.d.php-fpm  reload  #重新加载php-fpm

四、测试mcrypt扩展是否已安装成功

在网站目录下新建一个info.php测试页面,写上下面代码,保存

<?php phpinfo(); ?>

在浏览器中打开info.php 会看到如下的信息

说明mcrypt扩展已经安装成功

至此,Linux下php安装mcrypt扩展完成。

扩展知识:

安装php的mcrypt扩展

下载php下的mcrypt扩展或者直接下载php的完整安装包

http://php.net/releases/index.php网页下找到自己服务器的php版本,下载后tar解压(本人的是php5.3.3)

进入ext/mcrypt文件夹

[root@*_* 14:45 ~]# 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:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626

执行完后,会发现当前目录下多了一些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/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/lib64/php/modules/

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

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

[root@*_* 15:09 mcrypt]# cd /etc/php.d

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

[root@*_* 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
(3) 、重启apache,查阅phpinfo,mcrypt模块扩展是不是加载了?

在这里插入图片描述

yum install php-mcrypt 

猜你喜欢

转载自blog.csdn.net/ichen820/article/details/114693310