PHP7.0安装php_mcrypt扩展

转自:https://blog.csdn.net/liqihang_dev/article/details/82863896

情况:TP5报错:致命错误: Call to undefined function mcrypt_get_block_size()PHP7.0安装php_mcrypt扩展_第1张图片

某PHP项目中需要使用对称加密 mcrypt 加密库,由于PHP7已经将此扩展移除到PECL,需要手动安装,现记录一下。
通过 apt-cache search 名称查找 mcrypt:

$ sudo apt-get update
$ sudo apt-cache search mcrypt
gnupg-utils - GNU privacy guard - utility programs
overlayroot - use an overlayfs on top of a read-only root filesystem
golang-github-xordataexchange-crypt - Store/retrieve encrypted configs from etcd or Consul (CLI tool)
libcryptx-perl - Perl module that provides a self-contained crypto toolkit
libgringotts-dev - development files for the gringotts data encapsulation library
libgringotts2 - gringotts data encapsulation and encryption library
libmcrypt-dev - De-/Encryption Library development files
libmcrypt4 - De-/Encryption Library
libmrtd-dev - Development files for libmrtd0
libmrtd0 - MRTD - Machine-readable travel document library
libtomcrypt-dev - static library, header files and documentation for libtomcrypt
libtomcrypt1 - public domain open source cryptographic toolkit
mcrypt - Replacement for old unix crypt(1)
php7.0-mcrypt - libmcrypt module for PHP
php5.6-mcrypt - libmcrypt module for PHP
php7.1-mcrypt - libmcrypt module for PHP

可以看到,目前三个版本的(php5.6-mcrypt,php7.0-mcrypt,php7.1-mcrypt )可以选择。
安装 mcrypt 扩展

本例中的环境是通过 Laravel Homestead 安装的,有多个PHP版本。

    PHP7.0 安装 php7.0-mcrypt

sudo apt-get install php7.0-mcrypt
sudo apt-get install libmcrypt-dev;
sudo pecl install channel://pecl.php.net/mcrypt-1.0.0 
sudo echo 'extension=mcrypt.so'|sudo tee /etc/php/7.0/mods-available/mcrypt.ini
sudo ln -s /etc/php/7.0/mods-available/mcrypt.ini /etc/php/7.0/cli/conf.d/20-mcrypt.ini
sudo service php7.0-fpm restart

    PHP7.2 安装 php7.1-mcrypt

sudo apt-get install mcrypt php7.1-mcrypt
sudo apt-get install libmcrypt-dev;
sudo pecl install channel://pecl.php.net/mcrypt-1.0.1 
sudo echo 'extension=mcrypt.so'|sudo tee /etc/php/7.2/mods-available/mcrypt.ini
sudo ln -s /etc/php/7.2/mods-available/mcrypt.ini /etc/php/7.2/cli/conf.d/20-mcrypt.ini
sudo service php7.2-fpm restart

 

你可能感兴趣的:(php,tp5)