Laravel 需要 Mcrypt PHP 扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16830405/
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
Laravel requires the Mcrypt PHP extension
提问by Patrick Reck
I am trying to use the migrate
function in Laravel 4
on OSX
. However, I am getting the following error:
我正在尝试migrate
在Laravel 4
on 中使用该函数OSX
。但是,我收到以下错误:
Laravel requires the Mcrypt PHP extension.
As far as I understand, it's already enabled (see the image below).
据我了解,它已经启用(见下图)。
What is wrong, and how can I fix it?
出了什么问题,我该如何解决?
采纳答案by Jason Lewis
The web enabled extensions and command line enabled extensions can differ. Run php -m
in your terminal and check to see if mcrypt
is listed. If it's not then check where the command line is loading your php.ini
file from by running php --ini
from your terminal.
启用 Web 的扩展和启用命令行的扩展可能不同。php -m
在您的终端中运行并检查是否mcrypt
已列出。如果不是,则php.ini
通过php --ini
从终端运行来检查命令行从何处加载文件。
In this php.ini
file you can enable the extension.
在此php.ini
文件中,您可以启用扩展。
OSX
操作系统
I have heard of people on OSX running in to problems due to the terminal pointing to the native PHP shipped with OSX. You should instead update your bash profile to include the actual path to your PHP. Something like this (I don't actually use OSX so this might not be 100%):
我听说 OSX 上的人由于终端指向 OSX 附带的本机 PHP 而遇到问题。您应该更新您的 bash 配置文件以包含您的 PHP 的实际路径。像这样(我实际上不使用 OSX,所以这可能不是 100%):
export PATH=/usr/local/php5/bin:$PATH
Ubuntu
Ubuntu
On earlier versions of Ubuntu (prior to 14.04) when you run sudo apt-get install php5-mcrypt
it doesn't actually install the extension into the mods-available
. You'll need to symlink it.
在 Ubuntu 的早期版本(14.04 之前)上运行时,sudo apt-get install php5-mcrypt
它实际上并未将扩展安装到mods-available
. 您需要对其进行符号链接。
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
On all Ubuntu versions you'll need to enable the mod once it's installed. You can do that with php5enmod
.
在所有 Ubuntu 版本上,您都需要在安装后启用该 mod。你可以用php5enmod
.
sudo php5enmod mcrypt
sudo service apache2 restart
NOTES
- PHP 7.1 deprecated mcrypt and 7.2 has removed the mcrypt extension entirely
- Laravel 5.1 and later removed the need for mcrypt
笔记
- PHP 7.1 弃用了 mcrypt,7.2完全删除了 mcrypt 扩展
- Laravel 5.1 及更高版本不再需要 mcrypt
回答by JustinHo
Do you have MAMPinstalled?
你有安装MAMP吗?
Use which php
in the terminal to see which version of PHP you are using.
which php
在终端中使用以查看您使用的 PHP 版本。
If it's not the PHP version from MAMP, you should edit or add .bash_profile
in the user's home directory, that is : cd ~
如果不是 MAMP 的 PHP 版本,则应.bash_profile
在用户的主目录中编辑或添加,即:cd ~
In .bash_profile
, add following line:
在 中.bash_profile
,添加以下行:
export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
Edited:First you should use command cd /Applications/MAMP/bin/php
to check which PHP version from MAMP you are using and then replace with the PHP version above.
编辑:首先你应该使用命令cd /Applications/MAMP/bin/php
来检查你正在使用的 MAMP 的 PHP 版本,然后用上面的 PHP 版本替换。
Then restart
the terminal to see which PHP you are using now.
然后restart
终端看看你现在用的是哪个PHP。
And it should be working now.
它现在应该可以工作了。
回答by Bryan P
To those that uses XAMPP 1.7.3 and Mac
致那些使用 XAMPP 1.7.3 和 Mac 的人
- Go to Terminal
- Enter
which php
- If it says
/usr/bin/php
, then proceed to 3.
- If it says
- Enter
sudo nano ~/.bash_profile
(orsudo vim ~/.bash_profile
if you know how to use it) - Then paste this
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
- Ctrl+Othen enter to save, then Ctrl+Xto exit.
- Type
cd ~
- type
. .bash_profile
- restart terminal.
- Enter
which php
. If you did it right, it should be the same as the path in #4.
- 前往终端
- 进入
which php
- 如果显示
/usr/bin/php
,则继续执行 3。
- 如果显示
- 输入
sudo nano ~/.bash_profile
(或者sudo vim ~/.bash_profile
如果您知道如何使用它) - 然后粘贴这个
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
- Ctrl+O然后输入保存,然后Ctrl+X退出。
- 类型
cd ~
- 类型
. .bash_profile
- 重启终端。
- 输入
which php
。如果你做对了,它应该与#4中的路径相同。
The reason for the mcrypt error is because your Mac uses its native php, you need to change it to the one xampp has.
mcrypt 错误的原因是因为您的 Mac 使用其本机 php,您需要将其更改为 xampp 的一个。
P.S. I'd recommend using MAMP for Laravel 4 for Mac users, this issue will get resolved along with the php file info error without a sweat, and the php version of xampp is so outdated.
PS 我建议 Mac 用户为 Laravel 4 使用 MAMP,这个问题将随着 php 文件信息错误得到解决,而 xampp 的 php 版本已经过时了。
回答by oozzal
For non MAMP or XAMPP users on OSX (with homebrew installed):
对于 OSX 上的非 MAMP 或 XAMPP 用户(安装了自制软件):
brew install homebrew/php/php56-mcrypt
brew install homebrew/php/php56-mcrypt
Cheers!
干杯!
回答by mppfiles
Using Ubuntu, just
使用 Ubuntu,只需
sudo php5enmod mcrypt
did the trick for me. You don't need to restart Apache since you need to use PHP just from the CLI.
帮我解决了这个问题。您不需要重新启动 Apache,因为您只需从 CLI 中使用 PHP。
回答by Nanhe Kumar
In Ubuntu (PHP-FPM,Nginx)
在 Ubuntu 中(PHP-FPM,Nginx)
sudo apt-get install php5-mcrypt
After installing php5-mcrypt
安装 php5-mcrypt 后
you have to make a symlink to ini files in mods-available:
您必须在 mods-available 中创建指向 ini 文件的符号链接:
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
enable:
使能够:
sudo php5enmod mcrypt
restart php5-fpm:
重启 php5-fpm:
sudo service php5-fpm restart
回答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
i had a working laravel project on windows. when i copied it to ubuntu server , i started getting the mcrypt error. this after a lot of hours of trial and error
我在 Windows 上有一个工作的 Laravel 项目。当我将它复制到 ubuntu 服务器时,我开始收到 mcrypt 错误。这是经过很多小时的反复试验
getting artisan command working
让工匠命令工作
(if you are having mcrypt error while using artisan command line tool)
(如果您在使用 artisan 命令行工具时遇到 mcrypt 错误)
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
修复浏览器错误
(if you are having mcrypt error in browser when accessing local laravel index page)
(如果您在访问本地 Laravel 索引页面时在浏览器中遇到 mcrypt 错误)
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 Prateek Choudhary
For php-fpm installations on Ubuntu 14.04, the following worked for me :
对于 Ubuntu 14.04 上的 php-fpm 安装,以下对我有用:
sudo apt-get install php5-mcrypt
sudo apt-get install php5-mcrypt
This will create mcrypt.ini
file inside /etc/php5/mods-available/
这将mcrypt.ini
在里面创建文件/etc/php5/mods-available/
Then
然后
sudo php5enmod mcrypt
sudo php5enmod mcrypt
will create a symlink in: /etc/php5/fpm/conf.d/
将在以下位置创建符号链接: /etc/php5/fpm/conf.d/
Just restart php-fpm services
sudo service php5-fpm restart
只需重启 php-fpm 服务
sudo service php5-fpm restart
回答by JoeTidee
Or, use:
或者,使用:
sudo apt-get install php5-mcrypt
not sure if this will work on standard PHP installs - I installed php 5.5.7
using the package from :
不确定这是否适用于标准 PHP 安装 - 我php 5.5.7
使用以下软件包安装:
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
回答by Sagiruddin Mondal
For ubuntu try these steps if others are not working :
对于 ubuntu,如果其他人不工作,请尝试以下步骤:
cd ~
sudo apt-get remove php5-mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
sudo service apache2 restart
cd ~
sudo apt-get remove php5-mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
sudo service apache2 restart
Hope that will help. Thanks !
希望这会有所帮助。谢谢 !