php 致命错误:调用未定义的函数 mcrypt_encrypt()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2604435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined function mcrypt_encrypt()
提问by Jin Yong
NOTE:The libraries MCrypt support depend on have not been updated in years and MCrypt should no longer be considered a viable or secure method of encrypting data. What's more, MCrypt has been deprecated in PHP 5, and removed entirely in PHP 7. If you have any code that runs MCrypt you should refactor it to use a more modern encryption library.
注意:MCrypt 支持所依赖的库多年没有更新,MCrypt 不应再被视为一种可行或安全的数据加密方法。更重要的是,MCrypt 在 PHP 5 中已被弃用,并在 PHP 7 中完全删除。如果您有任何运行 MCrypt 的代码,您应该重构它以使用更现代的加密库。
Does anyone know why this error message: (Call to undefined function mcrypt_encrypt() )displays when I run the following code below?
有谁知道为什么会出现此错误消息:(Call to undefined function mcrypt_encrypt() )当我运行以下代码时显示?
Am I missing some steps perhaps any setting in PHP I have to do before this code can work?
在这段代码可以工作之前,我是否错过了一些步骤,或者我必须在 PHP 中进行的任何设置?
$key = 'password to (en/de)crypt';
$string = 'string to be encrypted';
$test = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key),
$string, MCRYPT_MODE_CBC, md5(md5($key)));
采纳答案by Anthony Forloney
What had worked for me with PHP version 5.2.8, was to open up php.iniand allow the php_mcrypt.dllextension by removing the ;, i.e. changing:
PHP 5.2.8 版对我有用的是通过删除来打开php.ini并允许php_mcrypt.dll扩展;,即更改:
;extension=php_mcrypt.dllto extension=php_mcrypt.dll
;extension=php_mcrypt.dll到 extension=php_mcrypt.dll
回答by flor
If you have recently updated to ubuntu 14.04 here is the fix to this problem:
如果您最近更新到 ubuntu 14.04,这里是解决此问题的方法:
$ sudo mv /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
$ sudo php5enmod mcrypt
$ sudo service apache2 restart
回答by Sabbir
For windows
窗户用
;extension=php_mcrypt.dll to extension=php_mcrypt.dll
then restart your apache server
For Redhat
对于红帽
sudo yum install php55-mcrypt //if php5.5
sudo yum install php-mcrypt //if less than 5.4
sudo service httpd restart //if apache 2.4
sudo /etc/init.d/httpd restart //if apache 2.2 or less
For Ubuntu
对于 Ubuntu
sudo apt-get install php5-mcrypt
sudo service apache2 restart //if server not reloaded automatically
Still not working?
还是行不通?
sudo php5enmod mcrypt && sudo service apache2 restart
须藤 php5enmod mcrypt && 须藤服务 apache2 重启
回答by dkamins
You don't have the mcrypt library installed.
您没有安装 mcrypt 库。
See http://www.php.net/manual/en/mcrypt.setup.phpfor more information.
有关更多信息,请参阅http://www.php.net/manual/en/mcrypt.setup.php。
If you are on shared hosting, you can ask your provider to install it.
如果您使用共享主机,您可以要求您的提供商安装它。
In OSX you can easily install mcrypt via homebrew
在 OSX 中,您可以通过自制软件轻松安装 mcrypt
brew install php54-mcrypt --without-homebrew-php
Then add this line to /etc/php.ini.
然后将此行添加到 /etc/php.ini。
extension="/usr/local/Cellar/php54-mcrypt/5.4.24/mcrypt.so"
回答by Fabian Thommen
If you are using PHP 7.2 or up:
如果您使用的是 PHP 7.2 或更高版本:
This function was DEPRECATED in PHP 7.1.0, and REMOVED in PHP 7.2.0.
这个函数在 PHP 7.1.0 中被弃用,在 PHP 7.2.0 中被移除。
source: http://php.net/manual/en/function.mcrypt-encrypt.php
来源:http: //php.net/manual/en/function.mcrypt-encrypt.php
So you have to replace the php code and find a solution without mcrypt.
所以你必须替换php代码并找到没有mcrypt的解决方案。
Or, I just found out, you can STILL use mcrypt in PHP 7.2.0, but you have to install it as a PHP Extension Community Library. (https://pecl.php.net/)
或者,我刚刚发现,您仍然可以在 PHP 7.2.0 中使用 mcrypt,但您必须将其安装为 PHP 扩展社区库。( https://pecl.php.net/)
On Debian/Ubuntu Linux distros:
在 Debian/Ubuntu Linux 发行版上:
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
then:
然后:
sudo pecl install mcrypt-1.0.1
Source: https://www.techrepublic.com/article/how-to-install-mcrypt-for-php-7-2/
来源:https: //www.techrepublic.com/article/how-to-install-mcrypt-for-php-7-2/
回答by Pierre de LESPINAY
Under Ubuntu I had the problem and solved it with
在 Ubuntu 下,我遇到了问题并解决了它
$ sudo apt-get install php5-mcrypt
$ sudo service apache2 reload
回答by alphayax
On ubuntu 14.10 :
在 Ubuntu 14.10 上:
Install module mcrypt
安装模块 mcrypt
sudo apt install php5-mcrypt
Enable module mcrypt on apache2
在 apache2 上启用模块 mcrypt
sudo a2enmod mcrypt
Reload module configuration
重新加载模块配置
sudo service apache2 restart
回答by Phil Lawlor
On Linux Mint 17.1 Rebecca - Call to undefined function mcrypt_create_iv...
在 Linux Mint 17.1 Rebecca - 调用未定义的函数 mcrypt_create_iv...
Solved by adding the following line to the php.ini
通过将以下行添加到 php.ini 解决
extension=mcrypt.so
After that a
在那之后
service apache2 restart
solved it...
解决了...
回答by Ahmad Vaqas Khan
I had the same issue for PHP 7version of missing mcrypt.
对于缺少 mcrypt 的PHP 7版本,我遇到了同样的问题。
This worked for me.
这对我有用。
sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
sudo apt-get upgrade
sudo service apache2 restart (if needed)
回答by nicky
If you are using php5-fpm do remeber to restart it, after installing mcrypt
如果您使用的是 php5-fpm,请记住在安装 mcrypt 后重新启动它
service php5-fpm restart
服务 php5-fpm 重启

