安装 php7.2-mcrypt 的问题
Posted
技术标签:
【中文标题】安装 php7.2-mcrypt 的问题【英文标题】:Issue in installing php7.2-mcrypt 【发布时间】:2018-06-24 19:43:47 【问题描述】:当我尝试从 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: command not found
在文档部分,已经明确声明它已被弃用,并且从安全角度来看将不再可用 - 从那时起,从 PHP 7.2.X 的发布版本开始。
但有些项目需要这些依赖项,以便在必要时执行所需的功能。我需要如何解决上述问题?
更新:
TL;DR:
我从投票中得到了很多回应发布的答案。需要根据操作系统架构级别对答案进行分类。 由于我使用共享服务器进行托管,因此有不止一个项目驻留在它上面并且使用 PHP 5.X.X 的版本进行编码,所以我决定降级到 PHP 7.1.X 在我的基于 Debian 的操作系统中默认支持 mcrypt 扩展。
正如我在链接中提到的 Installing mcrypt Extension on PHP 7.2,由 Server Pilot 社区提供。
这些人告诉过更新版本的 pecl-7.2 可用于在 PHP-7.2 上安装 mcrypt。不幸的是,它以
pecl7.2-sp: command not found
来自已执行的命令。后来网站页面更新了,所以那里的命令与执行时尝试的命令不匹配。
最后,无论哪种解决方案都适合您的操作系统架构级别,就去做吧!
或
如果以下方法不能解决根本原因。或者,您可以选择默认支持 mcrypt 扩展的 PHP 7.1.X 版本
【问题讨论】:
您应该寻求从现有应用程序中删除 mcrypt 使用,而不是将其安装在新服务器上。 尝试 pecl 而不是 pecl7.2-sp gist.github.com/arzzen/1209aa4a430bd95db3090a3399e6c35f 另一种可能是安装github.com/phpseclib/mcrypt_compat 【参考方案1】:我按照以下步骤使用 PECL 为 PHP7.2 安装 mcrypt。
-
安装 PECL
apt-get 安装 php-pecl
-
在安装 MCRYPT 之前,您必须安装 libmcrypt
apt-get install libmcrypt-dev libreadline-dev
-
使用 PECL 安装 MCRYPT 1.0.1
pecl 安装 mcrypt-1.0.1
-
安装成功后
您应该将“extension=mcrypt.so”添加到 php.ini
如果您需要任何帮助,请在下方评论。 :-)
重要!
根据php.net 参考,许多(所有)mcrypt 函数具有 自 PHP 7.1.0 起已弃用。依靠这个函数是 非常气馁。
【讨论】:
在 debian 上,对于第 1 步,使用apt-get install php-pear
来使用 PECL 命令。
php-pear 也用于 Ubuntu
如何在 amazon linux 1 上使用 php7.2 从源代码安装?
@TheOne 试试这个命令来安装 pear --> yum install php-pear 然后你从第 3 步开始
@PraneethNidarshan 它没有用。因为当我使用上面的命令行安装时,它带有 php5.3 包,我最终用 php 5.3 覆盖了我的 php7.2【参考方案2】:
@praneeth-nidarshan 几乎涵盖了所有步骤,除了一些:
检查是否已安装(或安装)pear:$ sudo apt-get install php-pear
sh: phpize: 未找到
错误:`phpize' 失败
$ sudo apt-get install php7.2-dev
$ sudo pecl install mcrypt-1.0.1
extension=mcrypt.so
添加到您的php.ini 配置文件中;如果您不知道它在哪里,请搜索:
$ sudo php -i | grep 'Configuration File'
【讨论】:
【参考方案3】: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安装成功后,需要在php.ini中添加mcrypt.so扩展。
输出将如下所示:
...
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
【讨论】:
Windows 中的 WAMP 怎么样? PHP > 7.0 @pragnesh-karia 虽然可以在 Windows 上安装该库,但如果您使用 linux Vagrant 机器,它将为您省去很多麻烦 这个答案没问题,但我还要安装php-dev
包。
@PrafullaKumarSahu 您需要安装 php-pear、php-dev 和 libmcrypt-dev 软件包才能运行这些命令。
@PragneshKaria 你找到解决方案了吗?【参考方案4】:
作为替代方案,您可以安装 7.1 版本的 mcrypt
并创建指向它的符号链接:
安装php7.1-mcrypt:
sudo apt install php7.1-mcrypt
创建符号链接:
sudo ln -s /etc/php/7.1/mods-available/mcrypt.ini /etc/php/7.2/mods-available
在sudo phpenmod mcrypt
启用mcrypt
后,它就可用了。
【讨论】:
经过数小时的研究,我需要的是最后一段!在我的情况下是:sudo phpenmod -v 7.3 mcrypt
【参考方案5】:
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 installatio 和 apache 使用的 php 版本。
【讨论】:
【参考方案6】:sudo apt install php-dev libmcrypt-dev php-pear
sudo pecl channel-update pecl.php.net
sudo pecl install mcrypt-1.0.1
最后,运行以下命令打开 PHP 配置文件
sudo nano /etc/php/7.2/cli/php.ini 然后将下面的行添加到文件中,就在 [PHP] 下方并保存...
extension=mcrypt.so
对于 Apache2
sudo nano /etc/php/7.2/apache2/php.ini
对于 nginx
sudo nano /etc/php/7.2/fpm/php.ini
你可以重启php
sudo service php7.2-fpm restart
【讨论】:
以上是关于安装 php7.2-mcrypt 的问题的主要内容,如果未能解决你的问题,请参考以下文章