安装 Laravel 时出错:需要 Mcrypt PHP 扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25006701/
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
Error Installing Laravel: Mcrypt PHP extension required
提问by Jake
I know there are a lot of questions about this on SO but none of them address my problem. I've checked everything they mention everything seems to indicate mcrypt is ok except when installing Laravel. Clearly I'm missing something.
我知道在 SO 上有很多关于此的问题,但没有一个能解决我的问题。我已经检查了他们提到的所有内容似乎都表明 mcrypt 没问题,除非安装 Laravel。显然我错过了一些东西。
When installing Laravel as directed (composer create-project laravel/laravel myproj --prefer-dist
) I get the error "Mcrypt PHP extension required" at what seems to be near the end of installation.
当按照指示 ( composer create-project laravel/laravel myproj --prefer-dist
)安装 Laravel 时,我在安装即将结束时收到错误“需要 Mcrypt PHP 扩展”。
As far as I can tell mcrypt isinstalled and enabled.
据我所知,mcrypt已安装并启用。
Composer uses /usr/bin/env php
作曲家使用 /usr/bin/env php
$ which composer ?
/usr/local/bin/composer
$ cat /usr/local/bin/composer
#!/usr/bin/env bash
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar $*%
php on my PATH is 5.5.10 from MAMP
我的 PATH 上的 php 是来自 MAMP 的 5.5.10
$ php --version
PHP 5.5.10 (cli) (built: Apr 10 2014 17:49:22)
$ which php
/Applications/MAMP/bin/php/php5.5.10/bin/php
Mcrypt is installed and enabled
Mcrypt 已安装并启用
$ php -m | grep mcrypt
mcrypt
$ php --info | grep mcrypt
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
$ php --ini
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.5.10/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php5.5.10/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
$grep mcrypt /Applications/MAMP/bin/php/php5.5.10/conf/php.ini ?
extension=mcrypt.so
I can see mcrypt support
enabled
in a phpinfo page via MAMP too.
我也可以mcrypt support
enabled
通过 MAMP 在 phpinfo 页面中看到。
What am I missing?
我错过了什么?
edit:I have export PATH="/Applications/MAMP/bin/php/php5.5.10/bin:$PATH"
in .bash_profile
and can confirm with echo $PATH
and which php
编辑:我已经export PATH="/Applications/MAMP/bin/php/php5.5.10/bin:$PATH"
在.bash_profile
和可以确认echo $PATH
和which php
update:a clue.
更新:一个线索。
If I edit /usr/local/bin/composer
to be:
如果我编辑/usr/local/bin/composer
为:
#!/usr/bin/env bash
echo $PATH
/usr/bin/env php --ini
and run composer
I get
然后运行composer
我得到
/usr/bin:/bin:/usr/sbin:/sbin
Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)
Scan for additional .ini files in: /Library/Server/Web/Config/php
Additional .ini files parsed: (none)
Why is that PATH different?
为什么那个 PATH 不同?
回答by Sojan V Jose
Getting Laravel working on Apache
让 Laravel 在 Apache 上工作
PHP version : PHP 5.5.9
PHP 版本:PHP 5.5.9
Ubuntu version : 14.04
Ubuntu 版本:14.04
After a lot of trial and error and searching around , this is what i discovered . i had a working laravel project on windows, i copied it to ubuntu server and started getting the mcrypt error.
经过大量的反复试验和搜索,这就是我发现的。我在 Windows 上有一个工作的 laravel 项目,我将它复制到 ubuntu 服务器并开始收到 mcrypt 错误。
getting artisan command working
让工匠命令工作
i did a lot of trial and error so each time i run the php5enmod command before, i had error messages. but on fresh install there was no error messages. after this step i got artisan command working
我做了很多尝试和错误,所以每次我运行 php5enmod 命令之前,我都会收到错误消息。但是在全新安装时没有错误消息。在这一步之后,我得到了工匠命令的工作
sudo rm /etc/php5/mods-available/mcrypt.ini
sudo apt-get purge php5-mcrypt
sudo apt-get install mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
fixing the browser error
修复浏览器错误
sudo nano /etc/php5/apache2/php.ini
add the following line under the dynamically compiled extensions section of php ini
在 php ini 的动态编译扩展部分下添加以下行
extension=mcrypt.so
restart the apache server , purge the laravel cache and everything working
重启apache服务器,清除laravel缓存,一切正常
回答by Sam Dufel
From what you've posted, it looks like composer is using a different PHP installation than your MAMP version. One workaround would be using the PHAR version instead:
从您发布的内容来看,composer 使用的 PHP 安装似乎与您的 MAMP 版本不同。一种解决方法是使用 PHAR 版本:
wget https://getcomposer.org/composer.phar
php composer.phar create-project laravel/laravel myproj --prefer-dist
If your CLI php is registering mcrypt as an installed module, this will resolve your installation issue.
如果您的 CLI php 将 mcrypt 注册为已安装的模块,这将解决您的安装问题。
回答by Jake
The only thing I can find to make this work is to edit /usr/local/bin/composer
and set the PATH in there like so:
我能找到的唯一方法是在其中编辑/usr/local/bin/composer
和设置 PATH,如下所示:
#!/usr/bin/env bash
export PATH="/Applications/MAMP/bin/php/php5.5.10/bin:$PATH"
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar $*
It's hacky and I'd still like to know what's up with my env but it works!
它很笨拙,我仍然想知道我的 env 是怎么回事,但它有效!
回答by Lazy H Yut
i had also encounter similar problem, and following command worked for me.
我也遇到过类似的问题,以下命令对我有用。
sudo apt-get install php5-mcrypt
sudo apt-get install php5-mcrypt
Hope it will works your too.
希望它也适用于您。