How to solve the “Mcrypt PHP extension required” problem during the Laravel installation

So, you decided to start using/study Laravel? Good!

When it comes to learn or practice with something new the most frustrating part is when this new “toy” won’t work out of the box. And that’s what happened to me the first time I tried to install Laravel on my MacBook Pro. I struggled with this problem for a good hour before finally figuring out what was wrong, and I thought would be great to write it down for future installations or to help other dudes like me that could encounter this problem. So, let’s take a look.


First step, before even start

Before even try to install Laravel you have to be sure that your machine has PHP and a Server Apache installed on it. The easiest way is to download MAMP and let him install everything for us, like PHP, Apache and MySql, something that you’ll need for sure if you’re intended to build something with Laravel.

Also, remember to install Composer to manage all the dependency of PHP and help you out a lot with Laravel, but not only.


Install Laravel

Open your Terminal and navigate to your favourite folder, the one you decided to use for your Laravel installation
cd /your-directory/your-folder
Always inside the Terminal write this code to activate Composer and tell him to download and install the latest version of Laravel for us
composer create-project laravel/laravel your-project-name --prefer-dist
And here comes the pain! This is the point where I got the current error message
Mcrypt PHP extension required.
Script php artisan clear-compiled handling the post-install-cmd event returned with an error.
Error Output:
create-project [-s|--stability="..."] [--prefer-source] [--prefer-dist] [--repository-url="..."] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--keep-vcs] [--no-install] [package] [directory] [version]

So, why is this happening? I’m not totally sure about the reason, but it looks like that Composer is trying to use the PHP version installed in the OS and not the one installed with MAMP, that it comes with the necessary Mcrypt extension.


Solve the problem

To solve this problem we have to edit our .bash_profile script and create an export to our MAMP php version. First of all open another Terminal instance and check your current php version with the command:
php -v
Your result should be something like this
PHP 5.5.10 (cli) (built: Apr 10 2014 17:49:22)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

Now that we have our PHP version, in my case 5.5.10, we can open our .bash_profile script
nano .bash_profile
and add our MAMP PHP version after the code already present
export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.10/bin

Exit the file and Save it. That’s it!

Now, if you run again the Composer command inside your folder, the installation should successfully complete.

Hope to be helpful to someone, see ya!


  • Deanna Riddlespur

    This helped me after nearly poking my eyeballs out and throwing my computer out the window, I found this tutorial. Ok so be sure you completely shut down your terminal.. do not just close the window or turn off the computer.

  • Deanna Riddlespur

    Any ideas on configuration of the database file in laravel? I have tried editing them to no avail.

    • To connect Laravel to your database you have to edit the file database.php in the directory app > config. What do you need to configure? MySql connection of a local or external database?
      If you can, try to me more accurate when you have a problem so I can easily and better understand it and give you better answers ^^

      P.S. I’m writing a new blog post I will publish in a couple of days about the first 5 things to do to properly configure Laravel after the installation. II’ll talk also about db config

  • Its just the basic Mamp setup of the database that comes with that. I have edited the file somewhat but I am not sure what I am doing wrong. I am working on a tutorial to try and get to know the laravel framework for an internship a classmate and I are doing this semester. I am gettin this error [PDOException]
    SQLSTATE[28000] [1045] Access denied for user ‘root’@’localhost’ (using pas
    sword: NO)

    • You need to setup a password for you database and use it inside your configuration file.
      Also be sure that your MAMP db is active and accessible via localhost.
      Please paste here also your db configuration code, of course only if has local settings, don’t past your private credentials

  • Taylor

    I downloaded the mcrypt program and I went followed your tutorial, but I am still getting the same error. Any suggestions?

    • Hi Taylor and thanks for the comment.
      What do you mean by “downloaded the mcrypt program”? There’s no mcrypt program, you need to install MAMP and Composer and then change your PHP in the bash_profile file.
      If you can please attach here your process with all the answers printed in your terminal.

  • Didnt solve the problem for me

    • Hi Sebastian and thank you for the comment.
      I’m sorry you couldn’t be able to solve your problem, did you follow every steps?
      What’s your PHP version?
      If you can give me more information I’ll try to help as much as I can.

  • Deanna Riddlespur

    Alessandro, This tutorial helped me when I fist started my internship, now my project is due is days and I am getting that error again, any idea why this is happening? Also I am trying to just go in and do it over again, do I need to be inside my MAMP or htdocs? Please and thank you

    • Deanna Riddlespur

      This is what my terminal is showing Mcrypt PHP extension required.
      lynn-paynes-MBP:MyDyn lynnpayne$

      • Deanna Riddlespur

        Hey I got it working. export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.18/bin
        export PATH=”$MAMP_PHP:$PATH”

        • Great job, you figured out what was the error.
          Just to give a quick heads up to other that could encounter this error, be careful while updating MAMP or your PHP version in general because your system could point to an outdated version of PHP.

          Cheers ^_^

  • Ricky

    Hey man, good tutorial, but this completely destroyed my terminal. It won’t even take my ls or cd commands any more – let alone the composer command. How do i fix this???

    • Thanks for the comment.
      What do you mean “destroy my terminal”?
      The code doesn’t affect in any way the functionality of the Terminal and it’s highly impossible that you damaged your terminal by mistake. Are you sure that you’re not still inside the .bash_profile?
      If you didn’t close the file it’s normal that your standard commands won’t work.
      Also, have you tried to open a new instance of the Terminal?
      Let me know!

  • Thank you!

  • Travis Michael Heller

    I just performed everything you had said above and still get the same error? I have wasted two days with this. what am i doing wrong and what else could i do. i just want to use the default Laravel build.

    • Hi Travis, I’m sorry to hear that.
      Can you please paste in your comment the results of the command php -v and what’s inside your bash_profile?


      • Travis Michael Heller

        I was able to figure it out, thank you

  • Jason

    Hi, I am a bit confused as to which directory I should edit my .bash_profile? my home directory?

    • Hi Jason and thank you for the comment!
      Yes, the .bash_profile file is inside your Home directory. The location depends on your operating system, as for example on OSX you can find it inside /Users/your-username/ folder.
      This file is hidden, so even if it’s there you can’t see it but you can open it via Terminal. Probably also it doesn’t exist, if you or other installations didn’t use it before, but also in this case you can create it via Terminal.

  • Jason Harris

    While reading your post about the MCrypt php error when downloading Laravel… and I did what you had said and I still got this error….

    – laravel/framework v5.0.16 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

    can you please help

    • Hi Jason, thank you for your comment.
      Can you please attach here the result of your php -v command and the code inside your .bash_profile file?

      Thank you

      • Jason Harris

        Here is the php -v

        PHP 5.5.17 (cli) (built: Sep 21 2014 21:13:38)

        Copyright (c) 1997-2014 The PHP Group

        Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

        and here is the .bash_profile

        export MAMP_PHP=/Applications/MAMP/bin/php/php.5.5.18/bin

        export PATH=”$HOME/.rbenv/bin:$PATH”

        • For what I can see your .bash_profile is pointing to php.5.5.18, while your current version of php is 5.5.17

          Change your PHP version inside the .bash_profile to php.5.5.17 and try again

  • Amr

    Would you please tell what is the equivalent solution for lampp on linux ?

    should it be something like this ?

    I tried :

    export LAMP_PHP=/opt/lampp/php

    export PATH=”$LAMP_PHP:$PATH”

    but didn’t work .

    • C

      Well, where is my bash.profile thingy?

      • Hello, your .bash_profile file is located in your Home folder, this folder variates based on your OS.
        On OSX is located in the folder named like your user login credential.
        Also remember that this is an hidden file, so you can’t see it unless you change the visibility option or you open it via Terminal.

    • Hello Amr, thanks for the comment.
      You should be able to locate your PHP installation by typing into the terminal this command:

      which php

      I haven’t had the chance to try Laravel on Linux, so this tutorial is mostly suited for OSX users.
      Hopefully this can help you.

  • Andrea Soro

    I keep finding this same solution on many forums but it doesn’t seem to take effect. I’m always stuck with the older version and it won’t change. Do you have any idea what the problem could be?

    • Alessandro

      Hi Andrea and thanks for your comment. I’m sorry you keep having the same problem and I will try to help you.
      Can you paste here the results of the steps I wrote in the tutorial? Like your PHP version and your bash_profile content.

  • Tom

    I had this problem in DigitalOcean and the problem was that mycrypt is not enabled by default, so I did:

    sudo php5enmod mcrypt
    sudo service apache2 restart

    Hope this helps 🙂

    • Hi Tom and thank you for sharing your experience, this will definetly be helpful for some one.

  • Andrew Clinton

    Thanks this helped a lot. I recently updated my MAMP version and so the php version in my .bash_profile was pointing to a php version not included in my new MAMP, haha. Go figure.

    • Alessandro

      Yup, that happens all the time and it’s really annoying. I’m glad I was helpful. Happy coding!

  • Michael Schlegel

    Thanks a lot for this tutorial. I am not interested in Laravel but I was trying to install php-encrytion. This did not work because the system of the php confusion you described in your tutorial. To be honest: I did not know anything about the “.bash_profile” and firstly I tried to place it in my the directory of my web app. Googling helped me to find .bash_profile within my HOME directory. I hope that this will help other people as well.

    • I’m glad this post was helpful even for non Laravel users. Thank you for your explanation, it will definitely be useful for others.

  • Hi, sorry for the late reply, your comment was hidden in my Pending bar.
    Anyway, I don’t have right now tutorials for Laravel, I’m planning to do those, but in the future.
    I suggest you to check Laracast and Tuts+. They a good amount of free tutorials about the topic.