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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:45:18  来源:igfitidea点击:

Laravel requires the Mcrypt PHP extension

phplaravellaravel-4mcrypt

提问by Patrick Reck

I am trying to use the migratefunction in Laravel 4on OSX. However, I am getting the following error:

我正在尝试migrateLaravel 4on 中使用该函数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?

出了什么问题,我该如何解决?

enter image description here

在此处输入图片说明

采纳答案by Jason Lewis

The web enabled extensions and command line enabled extensions can differ. Run php -min your terminal and check to see if mcryptis listed. If it's not then check where the command line is loading your php.inifile from by running php --inifrom your terminal.

启用 Web 的扩展和启用命令行的扩展可能不同。php -m在您的终端中运行并检查是否mcrypt已列出。如果不是,则php.ini通过php --ini从终端运行来检查命令行从何处加载文件。

In this php.inifile 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-mcryptit 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

笔记

回答by JustinHo

Do you have MAMPinstalled?

你有安装MAMP吗?

Use which phpin 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_profilein 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/phpto 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 restartthe 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 的人

  1. Go to Terminal
  2. Enter which php
    • If it says /usr/bin/php, then proceed to 3.
  3. Enter sudo nano ~/.bash_profile(or sudo vim ~/.bash_profileif you know how to use it)
  4. Then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
  5. Ctrl+Othen enter to save, then Ctrl+Xto exit.
  6. Type cd ~
  7. type . .bash_profile
  8. restart terminal.
  9. Enter which php. If you did it right, it should be the same as the path in #4.
  1. 前往终端
  2. 进入 which php
    • 如果显示/usr/bin/php,则继续执行 3。
  3. 输入sudo nano ~/.bash_profile(或者sudo vim ~/.bash_profile如果您知道如何使用它)
  4. 然后粘贴这个 export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
  5. Ctrl+O然后输入保存,然后Ctrl+X退出。
  6. 类型 cd ~
  7. 类型 . .bash_profile
  8. 重启终端。
  9. 输入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

More detail

更多详情

回答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.inifile 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.7using 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,如果其他人不工作,请尝试以下步骤:

  1. cd ~
  2. sudo apt-get remove php5-mcrypt
  3. sudo apt-get install php5-mcrypt
  4. sudo php5enmod mcrypt
  5. sudo service apache2 restart
  1. cd ~
  2. sudo apt-get remove php5-mcrypt
  3. sudo apt-get install php5-mcrypt
  4. sudo php5enmod mcrypt
  5. sudo service apache2 restart

Hope that will help. Thanks !

希望这会有所帮助。谢谢 !