问题

系统Ubuntu18.04
PHP代码中使用mcrypt_module_open()这个函数,调试时候报错:

PHP Fatal error: Uncaught Error: Call to undefined function mcrypt_module_open() in /home/aaron/Coding/php/cbc.php:4

原因

mcrypt在PHP 7.2中弃用了.

解决

依次在终端输入执行下面命令

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

最后一条命令需要按回车.

添加扩展信息:

sudo vi /etc/php/7.2/mods-available/20-mcrypt.ini

添加内容:extension=mcrypt.so

然后执行下面命令链接到conf.d

sudo ln -s /etc/php/7.2/mods-available/20-mcrypt.ini /etc/php/7.2/cli/conf.d/

检查扩展

php -i | grep mcrypt

输出以下信息代表OK

/etc/php/7.2/cli/conf.d/20-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

参考:
ubuntu 18.04 安装 php7.2-mcrypt - 简书