Call to undefined function  mcrypt_module_open() in CLI only, works fine when in browser

Posted on 2008-11-07
Last Modified: 2013-12-13

I'm encountering a weird problem.

I'm using xampp 1.6.4 on a  windows box. I'm trying encryption using the CLI for PHP and gets the error: "Call to undefined function  mcrypt_module_open() in ...."

Running phpinfo (php.exe -r phpinfo();) in the cli does not show mcrypt as enabled. Viewing the same script thru the browser, however, shows mcrypt as enabled.

Please help me in enabling mcrypt in CLI.

Question by:SWB-Consulting
    LVL 34

    Expert Comment

    by:Beverley Portlock
    Mcrypt does not always install properly on Windows. Try copying libmcrypt.dll from your PHP root folder (presumably C:\PHP) to \Windows\System32

    Author Comment

    Thanks bportlock,

    I tried this but still got the same error. I copied libmcypt.dll from my xampp\php to C:\Windows\system32 and restarted apache.

    Any more thoughts ?
    LVL 34

    Accepted Solution

    Ensure that the CLI version can see php.ini or copy php.ini to the CLI folder. From what you report it seems like the CLI version is not loading the mcrypt module.

    Author Comment

    Hi bportlock,

    Thanks You! I was finally able to make it work. The fact is, php cli in xampp has a separate php.ini file inside xampp/php where it gets the config from when using CLI. ( It usese the one in xampp/apache/bin when serving to a browser). Weird, huh ?

    Nevertheless, I am giving you the points because you helped me find the solution.
    LVL 34

    Expert Comment

    by:Beverley Portlock
    Thanks for the comment. It's always nice to know .... good luck with whatever you're doing.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now