php mcrypt 安装问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4809611/
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
problem with mcrypt installation
提问by Kide
I've asked the system admins to install mcrypton the server, and they say everything is OK. But when I run my simple script I get this.
我已经要求系统管理员在服务器上安装mcrypt,他们说一切正常。但是当我运行我的简单脚本时,我得到了这个。
Warning: mcrypt_get_iv_size() [function.mcrypt-get-iv-size]: Module initialization failed
警告:mcrypt_get_iv_size() [function.mcrypt-get-iv-size]:模块初始化失败
It's coming from this line:
它来自这一行:
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,MCRYPT_MODE_ECB);
Now, from this code:
现在,从这段代码:
$algorithms = mcrypt_list_algorithms("/usr/local/bin/mcrypt");
foreach ($algorithms as $cipher) {
echo "$cipher<br />\n";
}
I get:
我得到:
Warning: mcrypt_list_algorithms() [function.mcrypt-list-algorithms]: No algorithms found in module dir
警告:mcrypt_list_algorithms() [function.mcrypt-list-algorithms]:在模块目录中找不到算法
When I run this:
当我运行这个:
$modes = mcrypt_list_modes("/usr/local/bin/mcrypt");
foreach ($modes as $mode) {
echo "$mode <br />\n";
}
I get:
我得到:
Warning: mcrypt_list_modes() [function.mcrypt-list-modes]: No modes found in module dir
警告:mcrypt_list_modes() [function.mcrypt-list-modes]:在模块目录中找不到模式
However, running this command this command
但是,运行此命令此命令
which mcrypt; mcrypt -v
Produces:
产生:
/usr/local/bin/mcrypt
Mcrypt v.0.9.9 (x86_64-unknown-linux-gnu)
Linked against libmcrypt v.2.5.7
Copyright (C) 1998-2002 Nikos Mavroyanopoulos ([email protected])
Is mcryptinstalled/configured correctly?
是mcrypt的安装/配置是否正确?
UPDATE:
更新:
I did this:
我这样做了:
whereis libmcrypt
...and got the result:
...并得到结果:
libmcrypt: /usr/local/lib/libmcrypt /usr/local/lib/libmcrypt.so /usr/local/lib/libmcrypt.la
I've also changed:
我也变了:
$modes = mcrypt_list_modes("/usr/local/bin/mcrypt");
to...
到...
$modes = mcrypt_list_modes("/usr/local/lib/libmcrypt");
$algorithms = mcrypt_list_algorithms("/usr/local/lib/libmcrypt");
As recommended, but still get the error:
按照建议,但仍然出现错误:
Warning: mcrypt_list_modes() [function.mcrypt-list-modes]: No modes found in module dir in
警告:mcrypt_list_modes() [function.mcrypt-list-modes]:在模块目录中找不到模式
Then I went into the file manager in my CPanel to /usr/local/lib/libmcrypt
. The directory exists but it has no files in it...
然后我进入我的 CPanel 中的文件管理器到/usr/local/lib/libmcrypt
. 该目录存在,但其中没有文件...
Here is the print screen of the file manager.
Thanks.
谢谢。
回答by Akarsh Satija
Try this for your mcrypt problem:
试试这个解决你的 mcrypt 问题:
mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
sudo php5enmod mcrypt
sudo service apache2 restart
It's a bug with the location of the mcrypt.ini file.
这是 mcrypt.ini 文件位置的错误。
I had the same bug, I did a cp instead of a mv to be sure but it solved the problem.
我有同样的错误,我确实做了一个 cp 而不是 mv ,但它解决了问题。
For PHP not working, if you get phpmyadmin working (even with the mcrypt error), it means PHP is working (because phpmyadmin uses PHP). But in your example
对于 PHP 不工作,如果你让 phpmyadmin 工作(即使有 mcrypt 错误),这意味着 PHP 正在工作(因为 phpmyadmin 使用 PHP)。但在你的例子中
<? echo $row['details']; ?>
更改<?
<?
为<?php
<?php
并重试?回答by Ernest
On Ubuntu 14.04 just need to do only three steps as sudo:
在 Ubuntu 14.04 上只需要像 sudo 一样执行三个步骤:
apt-get install php5-mcrypt
php5enmod mcrypt
service apache2 restart
回答by netcoder
The mcryptalgorithms directory must be a directory containing the algorithms, not a binary. This means that this:
所述的mcrypt算法目录必须是包含算法的目录,而不是一个二值。这意味着:
$modes = mcrypt_list_modes("/usr/local/bin/mcrypt");
Should be this instead (assuming mcryptis installed is /usr/local/lib/libmcrypt
):
应该是这个(假设安装了mcrypt/usr/local/lib/libmcrypt
):
$modes = mcrypt_list_modes("/usr/local/lib/libmcrypt");
If the directory where libmcrypt
is installed is not that one above, you have to update your php.inisetting. Taken from php.ini:
如果libmcrypt
安装的目录不是上面的那个,你必须更新你的php.ini设置。取自php.ini:
[mcrypt]
; Directory where to load mcrypt algorithms
; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
;mcrypt.algorithms_dir=
; Directory where to load mcrypt modes
; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
;mcrypt.modes_dir=
If you have shell access, you can try this command to find the lib directory for your mcrypt installation:
如果你有 shell 访问权限,你可以尝试这个命令来为你的 mcrypt 安装找到 lib 目录:
whereis libmcrypt
or...
或者...
whereis mcrypt
Depending on your setup.
取决于您的设置。
回答by Charles
I had exactly the same problem.
我遇到了完全相同的问题。
> mcrypt -v
Mcrypt v.0.9.9 (sparc-sun-solaris2.10)
Linked against libmcrypt v.2.5.8
> mcrypt --list-hash
Supported Hash Algorithms:
crc32
md5
sha1
haval256
ripemd160
tiger
gost
[...]
> php CryptoTest.php
PHP Warning: mcrypt_list_modes(): No modes found in module dir in [...]
It was solved by reconfiguring and recompiling libmcrypt with these options:
它是通过使用以下选项重新配置和重新编译 libmcrypt 来解决的:
./configure --prefix=$YOUR_PATH/libmcrypt --enable-dynamic-loading --disable-posix-threads
Then in your php.ini :
然后在你的 php.ini 中:
mcrypt.algorithms_dir=<YOUR_PATH>/libmcrypt/lib/libmcrypt
mcrypt.modes_dir=<YOUR_PATH>/libmcrypt/lib/libmcrypt
回答by Placeholder
How to install mcrypt on MAC OSX:
如何在 MAC OSX 上安装 mcrypt:
Hello, tested and working on Mac OSX El Capitan:
您好,已在 Mac OSX El Capitan 上测试和运行:
1. Download mcrypt: http://www.viames.it/download/elcapitan/mcrypt.so
1.下载mcrypt:http: //www.viames.it/download/elcapitan/mcrypt.so
2. Place it in:
2. 放入:
/usr/lib/php/extensions/mcrypt
/usr/lib/php/extensions/mcrypt
3. Modify your 'php.ini'
3.修改你的'php.ini'
/etc/php.ini
/etc/php.ini
and add the following line:
并添加以下行:
extension = /usr/lib/php/extensions/mcrypt.so
4. Check if 'mcrypt' is loaded with the following command:
4. 使用以下命令检查“mcrypt”是否已加载:
php -m
php -m
5. Create a 'phpinfo.php' with content:
5. 用内容创建一个“phpinfo.php”:
<?php echo phpinfo(); ?>
and see if mcrypt is listed:
并查看是否列出了 mcrypt:
phpinfo() shows now mcrypt to be loaded
Yes, I know I'm a gangsta.
是的,我知道我是黑帮。
回答by Jose Manuel Gomez Alvarez
Architecture: Centos 6 / Apache 2.2 / Dual PHP installation (5.3 and 5.4)
架构:Centos 6 / Apache 2.2 / 双 PHP 安装(5.3 和 5.4)
UPDATE: This solution explains how to install the module mcrypt with PHP 5.4 manually from Remi's RPM on Centos 6, but this RPM requires glibc-2.14+, so this only is not enough to make it work, if your glibc is older than that.
更新:此解决方案解释了如何从 Centos 6 上的 Remi 的 RPM 手动安装带有 PHP 5.4 的模块 mcrypt,但此 RPM 需要 glibc-2.14+,因此如果您的 glibc 较旧,这仅不足以使其工作。
In my configuration, Yum install php-mcrypt*
showed as installed the version for 5.3
in normal root:
在我的配置中,Yum install php-mcrypt*
显示为5.3
在普通 root 中安装的版本:
php-mcrypt.x86_64 5.3.3-5.el6 @epel
However, 5.4is chrooted in /opt/rh/php54
但是,5.4已被 chroot/opt/rh/php54
Simply copying the 5.3 modules and config files does not work. The module fails initialization, that's why it does not appear in phpinfo(), this can be checked with
简单地复制 5.3 模块和配置文件是行不通的。模块初始化失败,这就是为什么它没有出现在 phpinfo() 中,这可以检查
/opt/rh/php54/root/usr/bin/php -v
The solution that worked for me is to download the Remi's RPM (although it's normally easier to install it by adding his Yum repository as discussed in the Comments) (https://www.rpmfind.net/linux/RPM/remi/fedora/25/x86_64/php54-php-mcrypt-5.4.45-12.fc25.remi.x86_64.html)
对我有用的解决方案是下载 Remi 的 RPM(尽管通过添加他在评论中讨论的 Yum 存储库通常更容易安装它)(https://www.rpmfind.net/linux/RPM/remi/fedora/ 25/x86_64/php54-php-mcrypt-5.4.45-12.fc25.remi.x86_64.html)
wget ftp://fr2.rpmfind.net/linux/remi/fedora/25/remi/x86_64/php54-php-mcrypt-5.4.45-12.fc25.remi.x86_64.rpm
extract the files with RPM2CPIO:
使用 RPM2CPIO 提取文件:
rpm2cpio php54-php-mcrypt-5.4.45-12.fc25.remi.x86_64.rpm |cpio -idmv
./opt/remi/php54/root/etc/php.d/mcrypt.ini
./opt/remi/php54/root/usr/lib64/php/modules/mcrypt.so
98 blocks
And copy to the chroot folder
并复制到chroot文件夹
cp ./opt/remi/php54/root/etc/php.d/mcrypt.ini /opt/rh/php54/root/etc/php.d/mcrypt.ini
cp ./opt/remi/php54/root/usr/lib64/php/modules/mcrypt.so /opt/rh/php54/root/usr/lib64/php/modules/
To check:
去检查:
/opt/rh/php54/root/usr/bin/php -v
And also:
并且:
<html>
<body>
<?php
phpinfo();
?>
</body>
</html>