本文翻译自:Laravel requires the Mcrypt PHP extension
I am trying to use the migrate
function in Laravel 4
on OSX
. 我正在尝试在OSX
上的Laravel 4
使用migrate
功能。 However, I am getting the following error: 但是,我收到以下错误:
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? 有什么问题,我该如何解决?
#1楼
参考:https://stackoom.com/question/18cM9/Laravel需要Mcrypt-PHP扩展
#2楼
The web enabled extensions and command line enabled extensions can differ. 启用Web的扩展名和启用命令行的扩展名可以不同。 Run php -m
in your terminal and check to see if mcrypt
is listed. 在终端中运行php -m
,然后检查是否列出了mcrypt
。 If it's not then check where the command line is loading your php.ini
file from by running php --ini
from your terminal. 如果不是,请从终端运行php --ini
,以检查命令行从何处加载php.ini
文件。
In this php.ini
file you can enable the extension. 在此php.ini
文件中,您可以启用扩展名。
OSX OSX
I have heard of people on OSX running in to problems due to the terminal pointing to the native PHP shipped with OSX. 我听说有人在OSX上遇到问题,原因是终端指向OSX随附的本机PHP。 You should instead update your bash profile to include the actual path to your PHP. 相反,您应该更新bash配置文件以包括PHP的实际路径。 Something like this (I don't actually use OSX so this might not be 100%): 这样的事情(我实际上没有使用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
. 在Ubuntu的早期版本(14.04之前的版本)上,当您运行sudo apt-get install php5-mcrypt
时,实际上并没有将扩展安装到mods-available
。 You'll need to symlink it. 您需要对其进行符号链接。
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. 在所有Ubuntu版本上,您都需要在安装Mod后启用它。 You can do that with php5enmod
. 您可以使用php5enmod
做到这php5enmod
。
sudo php5enmod mcrypt
sudo service apache2 restart
NOTES 笔记
- PHP 7.1 deprecated mcrypt and 7.2 has removed the mcrypt extension entirely PHP 7.1不推荐使用mcrypt,而7.2已完全删除了mcrypt扩展
- Laravel 5.1 and later removed the need for mcrypt Laravel 5.1及更高版本消除了对mcrypt的需求
#3楼
Do you have MAMP installed? 您安装了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. 现在应该可以正常工作了。
#4楼
To those that uses XAMPP 1.7.3 and Mac 对于使用XAMPP 1.7.3和Mac的用户
- Go to Terminal 前往终端
- Enter
which php
输入which php
- If it says
/usr/bin/php
, then proceed to 3. 如果显示/usr/bin/php
,则继续执行3。
- If it says
- Enter
sudo nano ~/.bash_profile
(orsudo vim ~/.bash_profile
if you know how to use it) 输入sudo nano ~/.bash_profile
(或sudo vim ~/.bash_profile
如果您知道如何使用它的话) - Then paste this
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
然后粘贴此export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
- Ctrl+O then enter to save, then Ctrl+X to exit. 按Ctrl + O,然后输入以保存,然后按Ctrl + X退出。
- Type
cd ~
输入cd ~
- type
. .bash_profile
类型. .bash_profile
. .bash_profile
- restart terminal. 重新启动终端。
- Enter
which php
. 输入which php
。 If you did it right, it should be the same as the path in #4. 如果操作正确,则该路径应与#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拥有的一个。
PS 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版本已经过时了。
#5楼
For non MAMP or XAMPP users on OSX (with homebrew installed): 对于OSX上的非MAMP或XAMPP用户(安装了自制软件):
brew install homebrew/php/php56-mcrypt
Cheers! 干杯!
#6楼
Expanding on @JetLaggy: 在@JetLaggy上扩展:
After trying again and again to modify .bash_profile with the MAMP directory, I changed the file permissions for the MAMP php directory and was able to get 'which php' to show the proper directory. 在尝试用MAMP目录修改.bash_profile之后,我更改了MAMP php目录的文件许可权,并且能够获取“哪个php”以显示正确的目录。 Trouble was that other functions didn't work, such as 'php -v'. 问题是其他功能不起作用,例如“ php -v”。
So I updated MAMP. 所以我更新了MAMP。 http://documentation.mamp.info/en/mamp/installation/updating-mamp http://documentation.mamp.info/en/mamp/installation/updating-mamp
This did the trick for my particular setup. 这为我的特定设置提供了窍门。 I had to adjust my PATH to reflect the updated version of PHP, but once I did, everything worked! 我必须调整PATH以反映PHP的更新版本,但是一旦完成,一切都会正常!