确认你的CentOS没有安装mcrypt库,如果已安装,跳过安装步骤
输入以下命令
yum list installed|grep mcrypt
显示以下信息,则说明已经安装过,若没有,则按以下两种方式安装
libmcrypt.x86_64 2.5.8-13.el7 @epel libmcrypt-devel.x86_64 2.5.8-13.el7 @epel libtomcrypt.x86_64 1.17-26.el7 @extras mcrypt.x86_64 2.6.8-11.el7 @epel php-mcrypt.x86_64 5.4.16-9.el7 @epel
yum命令懒人安装
yum install libmcrypt libmcrypt-devel mcrypt mhash
执行后会显示即将安装的相关库
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]:
输入y,回车
确定安装,最后显示
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!
安装完成后,到/usr/lib64/php/modules目录下看看是否存在mcrypt.so文件(我的并没有找到)
如果没有找到mcrypt.so文件,则执行以下命令
yum install php-mcrypt
显示
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package php-mcrypt.x86_64 0:5.4.16-9.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================== Package Arch Version Repository Size ======================================================================================== Installing: php-mcrypt x86_64 5.4.16-9.el7 epel 20 k Transaction Summary ======================================================================================== Install 1 Package Total download size: 20 k Installed size: 48 k Is this ok [y/d/N]:
输入y,回车确认
Downloading packages: php-mcrypt-5.4.16-9.el7.x86_64.rpm | 20 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : php-mcrypt-5.4.16-9.el7.x86_64 1/1 Verifying : php-mcrypt-5.4.16-9.el7.x86_64 1/1 Installed: php-mcrypt.x86_64 0:5.4.16-9.el7 Complete!
执行完成后,再次确认/usr/lib64/php/modules目录下看看是否存在mcrypt.so文件(我的已经存在)
接下来给你的php.ini添加一条extension=mcrypt.so记录(用命令find / -name "php.ini"查找php.ini所在路径)
[mcrypt] ; For more information about mcrypt settings see http://php.net/mcrypt-module-open extension=mcrypt.so
重启apache,扩展安装完成