當前位置: 首頁>>技術教程>>正文


安裝php7.2-mcrypt的問題

, , , ,

問題描述

當我嘗試從PHP 7.2.X版本加載mcrypt擴展模塊時。因此,我嘗試使用與我的PHP當前版本兼容的PECL庫,以進行安裝並遵循以下鏈接:安裝期間Installing mcrypt on PHP 7.2

以下是在終端上執行某些命令後獲得的結果。

root@YYY:/var/www/html/orocrm# apt install php-pear
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm4.0
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  php-pear
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 285 kB of archives.
After this operation, 2,107 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu xenial/main amd64 php-pear all 1:1.10.5+submodules+notgz-1+ubuntu16.04.1+deb.sury.org+1 [285 kB]
Fetched 285 kB in 1s (230 kB/s)   
Selecting previously unselected package php-pear.
(Reading database ... 215503 files and directories currently installed.)
Preparing to unpack .../php-pear_1%3a1.10.5+submodules+notgz-1+ubuntu16.04.1+deb.sury.org+1_all.deb ...
Unpacking php-pear (1:1.10.5+submodules+notgz-1+ubuntu16.04.1+deb.sury.org+1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up php-pear (1:1.10.5+submodules+notgz-1+ubuntu16.04.1+deb.sury.org+1) ...

YYY@YYY:/var/www/html/orocrm$ sudo apt-get -y install gcc make autoconf libc-dev pkg-config
[sudo] password for YYY: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libc6-dev' instead of 'libc-dev'
gcc is already the newest version (4:5.3.1-1ubuntu1).
make is already the newest version (4.1-6).
pkg-config is already the newest version (0.29.1-0ubuntu1).
libc6-dev is already the newest version (2.23-0ubuntu9).
The following package was automatically installed and is no longer required:
  libllvm4.0
Use 'sudo apt autoremove' to remove it.
Suggested packages:
  autoconf-archive gnu-standards autoconf-doc libtool
The following NEW packages will be installed:
  autoconf automake autotools-dev libsigsegv2 m4
0 upgraded, 5 newly installed, 0 to remove and 14 not upgraded.
Need to get 1,079 kB of archives.
After this operation, 3,998 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 libsigsegv2 amd64 2.10-4 [14.1 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 m4 amd64 1.4.17-5 [195 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 autoconf all 2.69-9 [321 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 autotools-dev all 20150820.1 [39.8 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 automake all 1:1.15-4ubuntu1 [510 kB]
Fetched 1,079 kB in 2s (447 kB/s) 
Selecting previously unselected package libsigsegv2:amd64.
(Reading database ... 215198 files and directories currently installed.)
Preparing to unpack .../libsigsegv2_2.10-4_amd64.deb ...
Unpacking libsigsegv2:amd64 (2.10-4) ...
Selecting previously unselected package m4.
Preparing to unpack .../archives/m4_1.4.17-5_amd64.deb ...
Unpacking m4 (1.4.17-5) ...
Selecting previously unselected package autoconf.
Preparing to unpack .../autoconf_2.69-9_all.deb ...
Unpacking autoconf (2.69-9) ...
Selecting previously unselected package autotools-dev.
Preparing to unpack .../autotools-dev_20150820.1_all.deb ...
Unpacking autotools-dev (20150820.1) ...
Selecting previously unselected package automake.
Preparing to unpack .../automake_1%3a1.15-4ubuntu1_all.deb ...
Unpacking automake (1:1.15-4ubuntu1) ...
Processing triggers for install-info (6.1.0.dfsg.1-5) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Setting up libsigsegv2:amd64 (2.10-4) ...
Setting up m4 (1.4.17-5) ...
Setting up autoconf (2.69-9) ...
Setting up autotools-dev (20150820.1) ...
Setting up automake (1:1.15-4ubuntu1) ...
update-alternatives: using /usr/bin/automake-1.15 to provide /usr/bin/automake (automake) in auto mode
Processing triggers for libc-bin (2.23-0ubuntu9) ...

YYY@YYY:/var/www/html/orocrm$ sudo apt-get -y install libmcrypt-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm4.0
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  libmcrypt-dev
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 83.7 kB of archives.
After this operation, 438 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 libmcrypt-dev amd64 2.5.8-3.3 [83.7 kB]
Fetched 83.7 kB in 0s (105 kB/s)       
Selecting previously unselected package libmcrypt-dev.
(Reading database ... 215484 files and directories currently installed.)
Preparing to unpack .../libmcrypt-dev_2.5.8-3.3_amd64.deb ...
Unpacking libmcrypt-dev (2.5.8-3.3) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libmcrypt-dev (2.5.8-3.3) ...

YYY@YYY:/var/www/html/orocrm$ sudo pecl7.2-sp install --nodeps mcrypt-snapshot
sudo: pecl7.2-sp: command not found

當我得到此錯誤類型為pecl7.2-sp時:找不到命令

從文檔部分可以清楚地表明,它已被棄用,從安全角度來看不再可用-從那時起,從PHP 7.2.X的發行版本開始。

但是某些項目需要這些依賴項,以便根據需要執行所需的功能。我該如何解決以上問題?


更新:

長話短說:

投票對發布的答案引起了很多反響。答案需要根據OS體係結構級別進行分類。由於我使用共享服務器進行托管,因此有多個項目駐留在該服務器上,這些代碼是用PHP 5.X.X版本編碼的,所以我決定降級到默認情況下在基於Debian的OS中支持mcrypt擴展的PHP7.1.X。

正如我在服務器飛行員社區Installing mcrypt Extension on PHP 7.2中的鏈接中已經提到的那樣。這些人告訴過pecl-7.2的更新版本可以在PHP-7.2上安裝mcrypt。不幸的是,它以發出的已執行命令的pecl7.2-sp: command not found結尾。稍後,網站頁麵進行了更新,因此該處的命令與執行時嘗試的命令不匹配。

最後,無論哪種解決方案都適合您的OS體係結構級別,就去做吧!

要麽

如果以下方法無法解決根本原因。另外,您可以使用默認支持mcrypt擴展的PHP 7.1.X版本

最佳方案

我按照以下步驟使用PECL為PHP7.2安裝mcrypt

  1. 安裝PECL

apt-get install php-pecl

  1. 在安裝MCRYPT之前,您必須安裝libmcrypt

apt-get install libmcrypt-dev libreadline-dev

  1. 使用PECL安裝MCRYPT 1.0.1

pecl install mcrypt-1.0.1

  1. 安裝成功後

You should add “extension=mcrypt.so” to php.ini

如果您需要任何幫助,請在下麵發表評論。 🙂

IMPORTANT !

According to php.net reference many (all) mcrypt functions have been DEPRECATED as of PHP 7.1.0. Relying on this function is highly discouraged.

次佳方案

Mcrypt PECL擴展

 sudo apt-get -y install gcc make autoconf libc-dev pkg-config
 sudo apt-get -y install libmcrypt-dev
 sudo pecl install mcrypt-1.0.1

出現提示時

 libmcrypt prefix? [autodetect] :

按[Enter]自動檢測。

成功安裝mcrypt trought pecl後,應將mcrypt.so擴展名添加到php.ini中。

輸出將如下所示:

...
Build process completed successfully
Installing '/usr/lib/php/20170718/mcrypt.so'    ---->   this is our path to mcrypt extension lib
install ok: channel://pecl.php.net/mcrypt-1.0.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=mcrypt.so" to php.ini

抓住安裝路徑並添加到cli和apache2 php.ini配置。

sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"

驗證擴展已安裝

運行命令:

php -i | grep "mcrypt"

輸出將如下所示:

/etc/php/7.2/cli/conf.d/mcrypt.ini
Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, convert.iconv.*, mcrypt.*, mdecrypt.*
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value

第三種方案

@ praneeth-nidarshan涵蓋了幾乎所有步驟,但有些步驟除外:

  • 檢查是否已安裝梨(或安裝):

$ sudo apt-get install php-pear

  • 如果尚未安裝,請安裝php7.2-dev以避免錯誤:

sh: phpize: not found

ERROR: `phpize’ failed

$ sudo apt-get install php7.2-dev

  • 使用pecl安裝mcrypt:

$ sudo pecl install mcrypt-1.0.1

  • 將擴展extension=mcrypt.so添加到您的php.ini配置文件中;如果您不知道它在哪裏,請搜索:

$ sudo php -i | grep 'Configuration File'

第四種方案

sudo apt-get install php-pear php7.x-dev

x是您的php版本,例如7.2,即php7.2-dev

apt-get install libmcrypt-dev libreadline-dev
pecl install mcrypt-1.0.1 

然後在”/etc/php/7.2/apache2/php.ini”中添加”extension=mcrypt.so”

這裏的php.ini取決於您的php安裝和apache使用的php版本。

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/10248.html,未經允許,請勿轉載。