Laravel requires the Mcrypt PHP extension

I am trying to use the migrate function in Laravel 4 on OSX . 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?

在这里输入图像描述


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.

In this php.ini file you can enable the extension.

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%):

export PATH=/usr/local/php5/bin:$PATH

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.

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 .

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

  • Do you have MAMP installed?

    Use which php in the terminal to see which version of PHP you are using.

    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 ~

    In .bash_profile , add following line:

    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.

    Then restart the terminal to see which PHP you are using now.

    And it should be working now.


    To those that uses XAMPP 1.7.3 and Mac

  • Go to Terminal
  • Enter which php
  • If it says /usr/bin/php , then proceed to 3.
  • Enter sudo nano ~/.bash_profile (or sudo vim ~/.bash_profile if you know how to use it)
  • Then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
  • Ctrl+O then enter to save, then Ctrl+X to exit.
  • Type cd ~
  • type . .bash_profile . .bash_profile
  • restart terminal.
  • Enter which php . If you did it right, it should be the same as the path in #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.

    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.

    链接地址: http://www.djcxy.com/p/71128.html

    上一篇: asp.net

    下一篇: Laravel需要Mcrypt PHP扩展