Maison > php教程 > php手册 > CentOS下php安装mcrypt扩展

CentOS下php安装mcrypt扩展

WBOY
Libérer: 2016-06-06 09:46:37
original
1243 Les gens l'ont consulté

(以下步骤均为本人实际操作,可能与你的安装方法有所区别,但我会尽量排除疑惑)

大致步骤(1)安装mcrypt,(2)安装php对mcrypt的扩展,(3)重启apache

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

[root@test-<span style="color: #800080;">206</span> ~]# yum list installed|<span style="color: #0000ff;">grep</span><span style="color: #000000;"> mcrypt
libmcrypt.x86_64                          </span><span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos           installed
libmcrypt</span>-devel.x86_64                    <span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos           installed
mcrypt.x86_64                             </span><span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">1</span>.el5                  installed
Copier après la connexion

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

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

yum <span style="color: #0000ff;">install</span> libmcrypt libmcrypt-devel mcrypt mhash
Copier après la connexion

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

<span style="color: #000000;">Dependencies Resolved

</span>================================================================================<span style="color: #000000;">
 Package              Arch        Version                   Repository     Size
</span>================================================================================<span style="color: #000000;">
Installing:
 libmcrypt            i386        </span><span style="color: #800080;">2.5</span>.<span style="color: #800080;">7</span>-<span style="color: #800080;">5</span>.el5               epel          <span style="color: #800080;">124</span><span style="color: #000000;"> k
 libmcrypt            x86_64      </span><span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span>.el5.centos        extras        <span style="color: #800080;">105</span><span style="color: #000000;"> k
 libmcrypt</span>-devel      i386        <span style="color: #800080;">2.5</span>.<span style="color: #800080;">7</span>-<span style="color: #800080;">5</span>.el5               epel          <span style="color: #800080;">103</span><span style="color: #000000;"> k
 libmcrypt</span>-devel      x86_64      <span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span>.el5.centos        extras         <span style="color: #800080;">10</span><span style="color: #000000;"> k
 mcrypt               x86_64      </span><span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">1</span>.el5               epel           <span style="color: #800080;">88</span><span style="color: #000000;"> k
 mhash                i386        </span><span style="color: #800080;">0.9</span>.<span style="color: #800080;">2</span>-<span style="color: #800080;">6</span>.el5               epel          <span style="color: #800080;">141</span><span style="color: #000000;"> k
 mhash                x86_64      </span><span style="color: #800080;">0.9</span>.<span style="color: #800080;">9</span>-<span style="color: #800080;">1</span>.el5.rf            rpmforge      <span style="color: #800080;">161</span><span style="color: #000000;"> k

Transaction Summary
</span>================================================================================<span style="color: #000000;">
Install       </span><span style="color: #800080;">7</span><span style="color: #000000;"> Package(s)
Upgrade       </span><span style="color: #800080;">0</span><span style="color: #000000;"> Package(s)

Total download size: </span><span style="color: #800080;">731</span><span style="color: #000000;"> k
Is this ok [y</span>/N]:
Copier après la connexion

确定安装,最后显示

<span style="color: #000000;">Installed:
  libmcrypt.x86_64 </span><span style="color: #800080;">0</span>:<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos
  libmcrypt</span>-devel.x86_64 <span style="color: #800080;">0</span>:<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">4</span><span style="color: #000000;">.el5.centos
  mcrypt.x86_64 </span><span style="color: #800080;">0</span>:<span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>-<span style="color: #800080;">1</span><span style="color: #000000;">.el5
  mhash.x86_64 </span><span style="color: #800080;">0</span>:<span style="color: #800080;">0.9</span>.<span style="color: #800080;">9</span>-<span style="color: #800080;">1</span><span style="color: #000000;">.el5.rf

Complete</span>!
Copier après la connexion

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

#<span style="color: #0000ff;">tar</span> -zxvf libmcrypt-<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span>.<span style="color: #0000ff;">tar</span><span style="color: #000000;">.gz
#cd libmcrypt</span>-<span style="color: #800080;">2.5</span>.<span style="color: #800080;">8</span><span style="color: #000000;">
#.</span>/<span style="color: #000000;">configure
#</span><span style="color: #0000ff;">make</span><span style="color: #000000;">
#</span><span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span> 说明:libmcript默认安装在/usr/local 
Copier après la connexion


3.安装mhash

#<span style="color: #0000ff;">tar</span> -zxvf mhash-<span style="color: #800080;">0.9</span>.<span style="color: #800080;">9.9</span>.<span style="color: #0000ff;">tar</span><span style="color: #000000;">.gz
#cd mhash</span>-<span style="color: #800080;">0.9</span>.<span style="color: #800080;">9.9</span><span style="color: #000000;">
#.</span>/<span style="color: #000000;">configure
#</span><span style="color: #0000ff;">make</span><span style="color: #000000;">
#</span><span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copier après la connexion

4.安装mcrypt

#<span style="color: #0000ff;">tar</span> -zxvf mcrypt-<span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span>.<span style="color: #0000ff;">tar</span><span style="color: #000000;">.gz
#cd mcrypt</span>-<span style="color: #800080;">2.6</span>.<span style="color: #800080;">8</span><span style="color: #000000;">
#LD_LIBRARY_PATH</span>=/usr/local/lib ./<span style="color: #000000;">configure
#</span><span style="color: #0000ff;">make</span><span style="color: #000000;">
#</span><span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copier après la connexion

最后,还是检查下,是否安装成功

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

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

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

进入ext/mcrypt文件夹

[root@*_* <span style="color: #800080;">14</span>:<span style="color: #800080;">45</span> ~]# cd php-<span style="color: #800080;">5.3</span>.<span style="color: #800080;">3</span>/ext/mcrypt/
Copier après la connexion

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

[root@*_* <span style="color: #800080;">14</span>:<span style="color: #800080;">48</span> mcrypt]# <span style="color: #0000ff;">whereis</span><span style="color: #000000;"> phpize    //为了确定phpize存在
phpize: </span>/usr/bin/phpize /usr/share/<span style="color: #0000ff;">man</span>/man1/phpize.<span style="color: #800080;">1</span><span style="color: #000000;">.gz
[root@</span>*_* <span style="color: #800080;">14</span>:<span style="color: #800080;">48</span><span style="color: #000000;"> mcrypt]# phpize
Configuring </span><span style="color: #0000ff;">for</span><span style="color: #000000;">:
PHP Api Version:         </span><span style="color: #800080;">20090626</span><span style="color: #000000;">
Zend Module Api No:      </span><span style="color: #800080;">20090626</span><span style="color: #000000;">
Zend Extension Api No:   </span><span style="color: #800080;">220090626</span>
Copier après la connexion

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

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

[root@*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">02</span> mcrypt]# <span style="color: #0000ff;">whereis</span> php-<span style="color: #000000;">config
php</span>-config: /usr/bin/php-config /usr/share/<span style="color: #0000ff;">man</span>/man1/php-config.<span style="color: #800080;">1</span><span style="color: #000000;">.gz
[root@</span>*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">02</span> mcrypt]# ./configure --with-php-config=/usr/bin/php-config
Copier après la connexion

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

configure: error: no acceptable C compiler found <span style="color: #0000ff;">in</span> $PATH
Copier après la connexion

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

[root@*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">06</span> mcrypt]# <span style="color: #0000ff;">make</span> && <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copier après la connexion

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

Installing shared extensions:     /usr/lib64/php/modules/
Copier après la connexion

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

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

[root@*_* <span style="color: #800080;">15</span>:<span style="color: #800080;">09</span> mcrypt]# cd /etc/php.d
Copier après la connexion

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

[root@*_* 15:17 php.d]# echo 'extension=mcrypt.so' > mcrypt.ini
Copier après la connexion

(3) 、重启apache,查阅phpinfo,mcrypt模块扩展是不是加载了?

 

 

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal