CentOS7下php安裝mcrypt擴充

來源:互聯網
上載者:User

轉自http://www.cnblogs.com/huangzhen/archive/2012/09/12/2681861.html


(以下步驟均為本人實際操作,可能與你的安裝方法有所區別,但我會盡量排除疑惑)

大致步驟(1)安裝mcrypt,(2)安裝php對mcrypt的擴充,(3)重啟apache

(1)確認你的linux沒有安裝mcrypt庫,如果已安裝,跳過安裝步驟

[root@test-206 ~]# yum list installed|grep mcryptlibmcrypt.x86_64                          2.5.8-4.el5.centos           installedlibmcrypt-devel.x86_64                    2.5.8-4.el5.centos           installedmcrypt.x86_64                             2.6.8-1.el5                  installed

以上顯示已經安裝過,若沒有,則按以下兩種方式安裝

(方法一)yum命令懶人安裝

yum install libmcrypt libmcrypt-devel 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 kTransaction Summary================================================================================Install       7 Package(s)Upgrade       0 Package(s)Total download size: 731 kIs 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.rfComplete!

(方法二)源碼編譯安裝,去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檔案夾

[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]# phpizeConfiguring for:PHP Api Version:         20090626Zend Module Api No:      20090626Zend Extension Api No:   220090626

執行完後,會發現目前的目錄下多了一些configure檔案,最後執行php-config命令就基本完成了

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

[root@*_* 15:02 mcrypt]# whereis php-configphp-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模組擴充是不是載入了。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.