如果在Ubuntu 20.04/18.04系统上遇到“E: Package ‘php-mcrypt’ has no installation candidate”的错误,只需要安装上PHP mcrypt扩展就能解决问题了。
PHP mcrypt扩展是mcrypt密码库的接口,它支持多种块算法,例如DES、TripleDES、Blowfish(默认)、3-WAY、SAFER-SK64、SAFER-SK128、TWOFISH、TEA、RC2和CBC、OFB、CFB、ECB密码模式下的GOST。
如果您尝试使用apt安装mcrypt,则会收到错误消息: $ sudo apt install php-mcrypt Reading package lists... Done Building dependency tree Reading state information... Done Package php-mcrypt is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'php-mcrypt' has no installation candidate
mcrypt扩展已移至PECL存储库,并且自PHP 7.2.0起不再与PHP捆绑在一起,PECL是所有已知PHP扩展的存储库,用户可以在其中下载和托管开发的PHP扩展。
使您的操作系统提取安装库中可用的软件包的最新列表: sudo apt update
在Ubuntu上安装开发工具: sudo apt update sudo apt install -y build-essential
确认make和gcc: $ gcc --version gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ make --version GNU Make 4.2.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
需要首先在Ubuntu 20.04/18.04上安装PHP、dev和pear扩展。 sudo apt install php php-pear php-dev libmcrypt-dev 相关参考:在Ubuntu 18.04/16.04中安装PHP 7.3/7.2/7.1/7.0和PHP 7模块的方法。
确认pecl命令在您的系统中可用: $ which pecl /usr/bin/pecl
PECL用法: $ pecl help 它会返回相关的帮助信息。 注: 用法:pecl [options] command [command-options] <parameters> 键入“pecl help options”以列出所有选项。 键入“pecl help shortcuts”以列出所有命令快捷方式。 键入“pecl help version”或“pecl version”以列出版本信息。 键入“pecl help <command>”以获取指定命令的帮助。
更新channels: $ sudo pecl channel-update pecl.php.net Updating channel "pecl.php.net" Update of Channel "pecl.php.net" succeeded $ sudo pecl update-channels Updating channel "doc.php.net" Update of Channel "doc.php.net" succeeded Updating channel "pear.php.net" Update of Channel "pear.php.net" succeeded Updating channel "pecl.php.net" Channel "pecl.php.net" is up to date
让我们搜索mcrypt扩展名: $ sudo pecl search mcrypt
您可以使用带有安装选项的pecl命令来安装mcrypt扩展: $ sudo pecl install mcrypt
当您看到提示时: libmcrypt prefix? [autodetect] : 请按Enter自动检测。
在Ubuntu 20.04 Linux机器上完成mcrypt extension的安装后,您应该获得如下输出信息: Build process completed successfully Installing '/usr/lib/php/20190902/mcrypt.so' install ok: channel://pecl.php.net/mcrypt-1.0.3 configuration option "php_ini" is not set to php.ini location You should add "extension=mcrypt.so" to php.ini 注:在php.ini文件中启用扩展名。
Ubuntu 20.04: $ sudo vim /etc/php/7.4/cli/php.ini extension=mcrypt.so $ sudo vim /etc/php/7.4/apache2/php.ini extension=mcrypt.so
Ubuntu 18.04: $ sudo vim /etc/php/7.2/cli/php.ini extension=mcrypt.so $ sudo vim /etc/php/7.2/apache2/php.ini extension=mcrypt.so
您可以使用以下命令确认模块已安装并启用: $ php -m | grep mcrypt mcrypt
如果使用Apache或Nginx Web服务器托管的应用程序,请重新启动它们。 重新启动Apache Web服务器: $ sudo systemctl restart apache2 参考:在Ubuntu/Debian/RHEL/CentOS中启动、停止或重新启动Apache的方法。 重新启动Nginx Web服务器: $ sudo systemctl restart nginx
以上就是您可以轻松地在Ubuntu 20.4和Ubuntu 18.04 Linux系统上安装PHP mcrypt扩展的方法。
相关主题 |