92

After I have upgraded my system from Ubuntu 13.04 to 13.10 several problems have occurred with apache, mysql and php configurations.

I solved most of them but I can't seem to get mCrypt library working. Package is installed so i don't need to apt-get it. Server works and everything seems fine, but when I try to run php artisan serve with Laravel 4, I get a message that mCrypt is required.

I did php --ri mcrypt and the output was Extension 'mcrypt' not present. I have tried putting extension=mcrypt.so to /etc/php5/apache2/php.ini but it didn't work.

Any ideas?

Output of dpkg --get-selections | grep php5

libapache2-mod-php5         install
php5                        install
php5-cli                    install
php5-common                 install
php5-gd                     install
php5-json                   install
php5-mcrypt                 install
php5-mysql                  install
php5-readline               install
Vuk Stanković
  • 7,864
  • 10
  • 41
  • 65

10 Answers10

273

I think I found the solution at launchpad.net.

sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available
sudo php5enmod mcrypt
sudo service apache2 restart

This worked for me.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Vuk Stanković
  • 7,864
  • 10
  • 41
  • 65
  • Thanks for this answer, in OpenCart 1.5.6 this issue was causing the error... Fatal error: Call to undefined function mcrypt_create_iv() in //system/library/encryption.php on line 8 – AndyGaskell Nov 01 '13 at 10:08
  • Of note, this solution did not work for me with Laravel/Artisan until I **also** sym-linked in /etc/php5/cli/conf.d – David M Mar 19 '14 at 13:50
  • I am getting this error.Which code i have to update?In which file i need to update?Kindly suggest.. – user2089987 Mar 21 '14 at 12:54
  • This was causing Webgility not to sync. Installing it fixed it up right nice. Thanks! – Ryan Apr 09 '14 at 13:38
  • Works with Laravel !‌Thank you <3 – Mehdi Maghrouni Apr 30 '14 at 20:43
  • in the case of Ubuntu 14.04/PHP5.5 this will need to be `sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/a pache2/mods-available` just a heads up. – ehime Jun 10 '14 at 19:17
  • 2
    With Ubuntu 14.04/PHP5.5 the first line is not needed. php5enmod makes the link. – Wolk Oct 04 '14 at 00:03
27

I had this problem with Ubuntu 14.04 and I did the following to resolve it:

sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt

sudo service apache2 restart
eaykin
  • 3,713
  • 1
  • 37
  • 33
  • 1
    This is what worked for me, I have PHP Version 5.5.9-1ubuntu4.4, and I didn't have a /etc/php5/conf.d directory. – flcoder Oct 19 '14 at 16:21
14

I also have this problem with Ubuntu 14.04 after install.

First enable the mcrypt

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

Add this command in any line

extension=mcrypt.so

Create conf.d folder in /etc/php5

sudo mkdir conf.d

And inside that folder create mcrypt.ini file

sudo gedit mcrypt.ini 

Then add this command to that file

extension=mcrypt.so

Then create a link to file

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

Enable mcrypt module

sudo php5enmod mcrypt

Restart apache

sudo service apache2 restart
Mark
  • 2,380
  • 11
  • 29
  • 49
Daroath
  • 382
  • 3
  • 16
  • 3
    You don't need `extension=mcrypt.so` in `php.ini`. It's working also without it, as php extensions (like mcrypt) are in separate `.ini` files. – machineaddict Aug 12 '14 at 10:39
  • @machineaddict For me adding the 'extension=mcrypt.so' worked after installing the mcrypt. Lubuntu 14.04 Trusty Thar. I was not automatically loaded – Clain Dsilva Apr 23 '15 at 04:49
11

From Ubuntu 13.10 to 14.04:

sudo php5enmod mcrypt
sudo service apache2 restart

Works for me.

László Papp
  • 51,870
  • 39
  • 111
  • 135
Aleftos
  • 111
  • 1
  • 6
  • For me: `WARNING: Module mcrypt ini file doesn't exist under /etc/php5/mods-available`. However, the file was located somewhere else. `sudo cp /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/` and ran the commands above. Taken from [www.devraju.com](http://www.devraju.com/about-me/ubuntu-13-1014-04-mcrypt-missing-fatal-error-undefined-function-mcrypt_encrypt/) – machineaddict Aug 12 '14 at 10:32
3

I also had this problem with Ubuntu 14.04 and Nginx,but the tip for me was restart the FPM service, so I did:

Install the library

apt-get install php5-mcrypt

Find the path

updatedb && locate mcrypt.so

Set the path of mcrypt.so inside the mcrypt.ini file located in /etc/php5/mods-available/mcrypt.ini

extension=/usr/lib/php5/20121212/mcrypt.so

And then restart the FPM service

service php5-fpm restart

Deric Lima
  • 1,972
  • 2
  • 24
  • 33
0

Another solution if the package is already installed:

sudo aptitude reinstall php5-mycript

This worked for me after doing upgrade

rreimi
  • 96
  • 1
  • 3
0

Try this code:

ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/20-mcrypt.ini
service apache2 restart
Anthony Shaw
  • 8,146
  • 4
  • 44
  • 62
Indrajeet Singh
  • 2,958
  • 25
  • 25
0

I had the same problem with PHP 5.5.14 running on Mac OS X Yosemite. I was trying to install Laravel 5.0. And when I tried to create a new project I got an error like below (even when I tried to start the laravel server with php artisan serve

Alejandros-MacBook-Pro:Documents Lexynux$ laravel new blog
Crafting application...
PHP Notice:  Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /Library/WebServer/Documents/blog/config/app.php on line 83
PHP Notice:  Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /Library/WebServer/Documents/blog/config/app.php on line 83
Generating optimized class loader
Compiling common classes
Compiling views
PHP Notice:  Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /Library/WebServer/Documents/blog/config/app.php on line 83
Application key [CCOPocoMjnJTx4AFXk64wqyTKyo3BlHq] set successfully.
Application ready! Build something amazing.
Alejandros-MacBook-Pro:Documents Lexynux$ 

So I just added the line below at the end of my php.ini file with the nano editor:

extension=mcrypt.so
sudo nano /etc/php.ini

Finally just restart the Terminal and restart the laravel app server with

php artisan serve

And it works fine!

alexventuraio
  • 8,126
  • 2
  • 30
  • 35
0

just found on php.net

Note, for Ubuntu, simply installing php5-mcrypt did not get mcrypt to work. You need to execute the following commands as root to enable it:

apt-get install php5-mcrypt
mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
php5enmod mcrypt
service apache2 restart

http://php.net/manual/en/mcrypt.installation.php#114609

SharkWeb
  • 361
  • 1
  • 5
0

Sometimes, this "problem" occurs because you entered an artisan command on your local machine instead of on your virtual machine. If you are using Homestead, mcrypt is already installed. Consider it a reminder to homestead ssh

Chukky Nze
  • 720
  • 3
  • 13