(以下步驟均為本人實際操作,可能與你的安裝方法有所區別,但我會盡量排除疑惑)
大致步驟(1)安裝mcrypt,(2)安裝php對mcrypt的擴展,(3)重啟apache
(1)、確認你的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
以上顯示已經安裝過,若沒有,則按以下兩種方式安裝
(方法一)yum命令懶人安裝
yum install libmcrypt libmcrypt-devel php-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!
使用方法一注意:默認yum源里面沒有這幾個庫文件,不能使用yum安裝,需呀安裝第三方源
安裝第三方源可能升級你的部分程序,導致出錯,比如升級php導致部分api不能使用,謹慎使用
################################################### wget http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt rpm --import RPM-GPG-KEY.dag.txt rpm -ivh rpmforge-release-0.5.2-2.el6.rf.i686.rpm vi /etc/yum.repos.d/rpmforge.repo #修改rpmforge yum源優先級,priority=12 ################################################## rpm -ivh http://download1.rpmfusion.org/free/el/updates/testing/6/i386/rpmfusion-free-release-6-0.1.noarch.rpm vi /etc/yum.repos.d/rpmfusion-free-updates-testing.repo #修改rpmfusion yum源優先級,priority=13 ############################################## #下載 wget http://www.atomicorp.com/installers/atomic #安裝 sh ./atomic #修改atomic yum源優先級, vi /etc/yum.repos.d/atomic.repo #priority=14
參考:http://blog.chinaunix.net/uid-20754878-id-3092063.html
(方法二)源碼編譯安裝,去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://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
原文:http://www.cnblogs.com/huangzhen/archive/2012/09/12/2681861.html