461

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?

enter image description here

8

22 Answers 22

344

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.

13
  • 19
    You don't need MAMP to get Mcrypt. Commented Jul 18, 2013 at 8:06
  • 49
    of course you don't need MAMP to get Mcrypt. this answer is just for people who have multiple versions of PHP installed on their computer, say XAMPP or MAMP, or others.
    – JustinHo
    Commented Jul 19, 2013 at 3:37
  • Similarly, for AMPPS users: export PATH=/Applications/AMPPS/php-5.4/bin:$PATH ...assuming you're shooting for 5.4.xx, there's also 5.3 and 5.5 in there. Commented Dec 19, 2013 at 17:04
  • 7
    Everybody does not use MAMP, you have an answer for the rest of people? Commented Jan 12, 2015 at 1:49
  • 2
    Just thought I'd point out, the cd ~ is very important, you must open the .bash_profile that exists there, ALSO important is you must close your terminal and re-open so that the new bash variables are loaded. Just make sure to run which php to verify your change has applied, happy coding!
    – wired00
    Commented Jan 21, 2015 at 1:37
305

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

10
  • 4
    this worked for me on Ubuntu, thanks! Weird how sudo apt-get install php5-mcrypt doesn't actually install the extension fully.
    – Aristides
    Commented Mar 13, 2014 at 20:29
  • Ubuntu 13.10 - I also had to install mcrypt itself Commented Apr 1, 2014 at 18:43
  • 1
    Apparently it had already installed the mcrypt ini into mods-available, i just wasn't aware of the php5enmod command. Using that makes it work like a charm. Thanks! Commented Sep 30, 2014 at 21:15
  • So just on this, I have mcrypt listed when I go php -m, when I go which php it says /usr/local/bin/php. Ive tried installing mcrypt with brew and seemed to have worked.. But Laravel still says Mcrypt PHP extension required. Commented Oct 10, 2014 at 23:42
  • 1
    Like @imkingdavid I also did not require the symbolic link. php5enmod was sufficient. Ubuntu 14.04 LTS
    – Brett
    Commented Dec 22, 2014 at 21:31
143

To those that uses XAMPP 1.7.3 and 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_profile if you know how to use it)
  4. Then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
  5. Ctrl+O then enter to save, then Ctrl+X to 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.

The reason for the mcrypt error is because your Mac uses its native php, you need to change it to the one xampp has.

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.

6
  • 12
    Also a good answer! Should be this for MAMP: "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH"
    – Foxinni
    Commented Aug 25, 2013 at 9:32
  • 3
    for those who doesn't have ~/.bash_profile, try checking the ~/.bashrc
    – Ironwind
    Commented Oct 16, 2013 at 8:28
  • 6
    runs the .bash_profile immediately, normally you need to restart for those bash to run
    – Bryan P
    Commented May 15, 2014 at 0:17
  • Something bad happened and now my terminal would not even recognise sudo Commented Nov 25, 2014 at 16:14
  • It works on lampp too, just change the path to export PATH="/opt/lampp/bin:$PATH"
    – JTC
    Commented Jul 15, 2016 at 20:38
86

For non MAMP or XAMPP users on OSX (with homebrew installed):

brew install homebrew/php/php56-mcrypt

Cheers!

3
  • 1
    I was worried that this wouldn't work with native OSX PHP, but I just installed that and I didn't have to mess around with my PATH or anything. Just works. Nice one.
    – Lauren
    Commented Jun 20, 2014 at 23:32
  • 3
    It would be great to have this answer appended to the leading answers on this thread, to make it a more comprehensive resource. Thanks for the quick advice, as Lauren mentioned, this really fixes the problem. Commented Dec 3, 2014 at 4:41
  • 4
    This is actually $ brew install homebrew/php/php55-mcrypt, otherwise got Error: No available formula with the name "php55-mcrypt" Commented Dec 29, 2015 at 20:52
46

Using Ubuntu, just

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.

0
38

In Ubuntu (PHP-FPM,Nginx)

sudo apt-get install php5-mcrypt

After installing php5-mcrypt

you have to make a symlink to ini files in mods-available:

sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini

enable:

sudo php5enmod mcrypt

restart php5-fpm:

sudo service php5-fpm restart

More detail

1
  • I ran sudo aptitude -y install php5-mcrypt, followed by sudo php5enmod mcrypt and sudo service php5-fpm restart. (I skipped the soft linking step). It worked :)
    – Aditya M P
    Commented Jan 21, 2015 at 2:11
25

Getting Laravel working on Apache

PHP version : PHP 5.5.9

Ubuntu version : 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

getting artisan command working

(if you are having mcrypt error while using artisan command line tool)

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

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)

sudo nano /etc/php5/apache2/php.ini

add the following line under the dynamically compiled extensions section of php ini

extension=mcrypt.so

restart the apache server , purge the laravel cache and everything working

1
  • If you are working on php docker image, you also need to run docker-php-ext-install mcrypt. Tested on image: php:5.6.31-apache. Without that, php -m does not show mcrypt.
    – Ewa
    Commented Sep 18, 2017 at 9:54
17

For php-fpm installations on Ubuntu 14.04, the following worked for me :

sudo apt-get install php5-mcrypt

This will create mcrypt.ini file inside /etc/php5/mods-available/

Then

sudo php5enmod mcrypt

will create a symlink in: /etc/php5/fpm/conf.d/

Just restart php-fpm services sudo service php5-fpm restart

17

For ubuntu try these steps if others are not working :

  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 !

17

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 :

sudo add-apt-repository ppa:ondrej/php5 
sudo apt-get update
14

This solved it for me on my Linux Mint local enviroment https://askubuntu.com/questions/350942/cannot-get-mcrypt-for-php5

I needed to make a symlink to my /etc/php5/conf.d/mcrypt.ini file in the following folders /etc/php5/apache2/conf.d/mcrypt.ini and /etc/php5/cli/conf.d/mcrypt.ini

14

My OS is Yosemite.

I resolve this issue, by finding configuration paths:

php --ini

Example output:

Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File:         /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed:      (none)

Next steps:

  1. Rename or Delete php55 ini file
  2. Create symlink
  3. Restart Apache server

Commands:

mv /usr/local/etc/php/5.5/php.ini /usr/local/etc/php/5.5/php.ini.default
ln -s /etc/php.ini /usr/local/etc/php/5.5/php.ini
sudo apachectl restart

Then you can check your php modules via:

php -m
14

Just for yumers,

yum install php-mcrypt
service httpd restart
chown -R apache:apache apppath

Maybe you need install remi repo

13

You need an all in one environment. You may use MAMP or XAMPP or any other tools. After installing one of these tools you will need to edit(create) your .bash_profile(Assuming that you use bash).

Or even simple and more professional you can use Laravel Homestead.

Here is a link to official documentation: http://laravel.com/docs/5.0/homestead

Also Jeffrey has a free tutorial about it: https://laracasts.com/series/laravel-5-fundamentals/episodes/2

I advice you to go with homestead because you will preinstall all of the following tools.

  • Ubuntu 14.04
  • PHP 5.6
  • HHVM
  • Nginx
  • MySQL
  • Postgres
  • Node (With Bower, Grunt, and Gulp)
  • Redis
  • Memcached
  • Beanstalkd
  • Laravel Envoy
  • Fabric + HipChat Extension
10

For those who still come here today:

Laravel does not need mcrypt extension anymore. mcrypt is obsolete, the last update to libmcrypt was in 2007. Laravel 4.2 is obsolete too and has no more support. The best (=secure) solution is to update to Laravel 9.x+ (Laravel 8.x is still okay. But if you are upgrading, then upgrade to the latest version).

Mcrypt was removed from Laravel in June 2015: https://github.com/laravel/framework/pull/9041

2
  • I fixed my issue by running homestead provision
    – user5283119
    Commented Mar 15, 2018 at 17:05
  • I still came here today. and Still using Laravel 4.2
    – Jovylle
    Commented Apr 27, 2022 at 18:05
9

Expanding on @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. Trouble was that other functions didn't work, such as 'php -v'.

So I updated 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!

9

On OS X

Using MAMP

Enter the command which php in the terminal to see which version of PHP you are using. If it's not the PHP version from MAMP, the $PATH variable used by Bash will need to be updated.

First, you should use command "cd /Applications/MAMP/bin/php" to check which php version from MAMP and take note of the version (eg, php5.6.7).

Once you know the version, you should edit the ~/.bash_profile file (that is, the .bash_profile that is in your home directory) and add an export line:

    export PATH=/Applications/MAMP/bin/php/php5.6.7/bin:$PATH

Make sure that you replace php5.6.7 with the version of PHP that you have selected in MAMP.

Once the file has been saved, make sure that you close close your Terminal and open it again. Once that has been done, you will be using the PHP that ships with MAMP.


One way to easily find what the line should be that you need to put inside your .bash_profile is to run the following command inside your terminal:

    echo export PATH=`cat /Applications/MAMP/conf/apache/httpd.conf \
         | grep php | grep -i LoadModule | head -n1 \
         | sed -e 's/^[^\/]*\/\(.*\)\/mod.*/\/\1/'`/bin:\$PATH

Copying and pasting those three lines into your terminal will correctly output the PHP version that has been selected inside the MAMP control panel.

Using Homebrew/MacPorts

Make sure that your path contains /usr/local/bin/ (Homebrew) or /opt/local/bin (MacPorts) if you are using PHP that comes with either of these two package managers.

Checking the PHP path with MacPorts

You can find the exact location of PHP using MacPorts with the following command:

port contents php70 | grep bin/php

Note that you should replace php70 with the version of PHP that you have installed.

Check the PHP path with Homebrew-php

Homebrew-php (https://github.com/Homebrew/homebrew-php) is a tap that has various different versions of PHP.

You can find the exact location of PHP using Homebrew with the following command:

brew --prefix homebrew/php/php56

Note that you should replace php56 with the version of PHP that you have installed.

7

in Ubuntu 14.04

sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt

Ubuntu 16.04

sudo apt-get install php-mcrypt
sudo phpenmod mcrypt

Ubuntu 18.04

sudo apt install php7.0-mcrypt
sudo phpenmod mcrypt

or

sudo apt install php7.2-mcrypt
sudo phpenmod mcrypt
5

If you are using Z Shell, just do the following:

  1. Open terminal
  2. sudo nano ~/.zshrc
  3. Paste this; export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH
  4. Save
  5. Run source ~/.zshrc
  6. Run which php - you should get the MAMP 5.6.10 path

5.6.10 is the version of PHP you set in your MAMP.

3

OSX with brew

$ brew install mcrypt php70-mcrypt

I am running PHP 7.0.x, so change "php70" to your version, if you are using a different version.
As stated in other answers, you can see your php version with $ php -v.

0

This solution is for PHP 7.4.X on WAMP in Windows 10 (It will work for others versions if you manage to find the php_mcrypt.dll file for PHP version that you need).

For other PHP versions you may find the php_mcrypt.dll file in https://pecl.php.net/package/mcrypt or in php windows binaries file: in PHP windows binaries files in ext/ folder https://windows.php.net/downloads/releases/

-1

sudo php install mcrypt

sudo php5enmod mcrypt

1
  • 1
    While your comment might technically be true we strive to include some explanation to your answers here on StackOverflow. Furthermore it seems like OP already installed mcrypt, could you expand on why you believe this will fix OP's problem?
    – milo526
    Commented Sep 18, 2018 at 8:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.