phpenmod mcrypt and phpenmod mbstring return errors

43,878

Solution 1

Install them first:

sudo apt install php7.0-mcrypt && sudo apt install php7.0-mbstring

Then enable them with:

sudo a2enmod mcrypt
sudo a2enmod mbstring

Update

Based on the extensive research I believe a bug exist that prevents your php cli working well with php mcrypt.

Source:

Can't use PHP extension Mcrypt in Ubuntu 13.10 (Nginx, PHP-FPM)

php is not working well on ubuntu 13.10 and mcrypt is missing in phpmyadmin

To confirm that mcrypt is enabled in apache follow these steps:

  1. Create a php file called info.php put this code in it:

    <?php echo phpinfo(); ?>
    
  2. Put the file in /var/www/html or your server root

  3. Access it from the brower at say IP/info.php or localhost/info.php

  4. Look at the out and you will find that mcrypt and mbstring are enabled

    enter image description here

    As you can see, its enabled in apache, but inaccessible from php CLI hence the error messages.

  5. To confirm its working [as I have this problem also] I did the following:

    • installed prestashop application, and since one of the requirements of prestashop is php mcrypt it would have thrown an error and refused to proceed if mcrypt was not enabled on apache.

Simple put based on your the if your apache information page displays these modules as enabled then it is. The error seen are a result of php CLI having issues with mcrypt which has been noted to be a bug. Seen in earlier versions of php but now present in php 7

Solution 2

I had issues with the above solutions but found this:

https://www.techrepublic.com/article/how-to-install-mcrypt-for-php-7-2/

Essentially, build it yourself:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install php7.2-dev
sudo apt-get -y install libmcrypt-dev

Once the dependencies have been installed, you can install mcrypt with the command:

sudo pecl install mcrypt-1.0.1

From there I needed to add:

 /etc/php/7.2/mods-available/mcrypt.ini

Which looked like this:

; configuration for php mcrypt module
; priority=20
extension=mcrypt.so

Then

sudo phpenmod mcrypt
sudo systemctl restart apache2.service

Solution 3

If their both installed and the error persist, Try to make a symlink to ini files in mods-available

Here is how to do it:

sudo ln -s /etc/php7/conf.d/mcrypt.ini /etc/php/7.0/mods-available/mcrypt.ini

sudo ln -s /etc/php7/conf.d/mbstring.ini /etc/php/7.0/mods-available/mbstring.ini
Share:
43,878

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I use a minimal server environment of ubuntu16.04.1, Apache2, MySQL and PHP 7.0.8.1. I've installem AMP via: apt-get install lamp-server^.

    I also installed PHPmyadmin manually via:

    cd /var/www/html
    wget https://files.phpmyadmin.net/phpMyAdmin/4.6.5.2/phpMyAdmin-4.6.5.2-all-languages.zip
    find ./ -type f -name '*phpMyAdmin*.zip' -exec unzip {} \; # We can also do unzip \*phpMyAdmin*.zip ...
    find ./ -type d -name 'phpMyAdmin-*' -exec mv {} phpmyadmin \;
    

    PHPmyadmin is bootstrapped but to use it fully functionally, AFAIK I aslo need to do:

    phpenmod mcrypt
    phpenmod mbstring
    

    Yet these respectively return errors:

    Module mcrypt ini file doesn't exist under /etc/php/7.0/mods-available
    
    Module mbstring ini file doesn't exist under /etc/php/7.0/mods-available
    

    I never had these errors before. Are these modules redundant for PHPmyadmin in current releases or when not installed via apt-get install?

    • George Udosen
      George Udosen over 7 years
      try sudo a2enmod mcrypt and sudo a2enmod mbstring
    • muru
      muru over 7 years
      You did install php-mcrypt and php-mbstring, right?
    • George Udosen
      George Udosen over 7 years
      Is the issue resolved ?
    • Admin
      Admin over 7 years
      It seems I can access PMA without installing these as you shown in the answer so I wonder if there is an issue at all (the only reason I wanted to install this is because I thought they are missing for PMA but it seems in latest releases we just dont need them).
  • Admin
    Admin over 7 years
    Brings ERROR: Module mcrypt does not exist!.
  • George Udosen
    George Udosen over 7 years
    what version of php are you using ?
  • Admin
    Admin over 7 years
    I use version 7.0.8.
  • George Udosen
    George Udosen over 7 years
    Then do sudo apt install php7.0-mcrypt && sudo apt install php7.0-mbstring its like its not installed.
  • Admin
    Admin over 7 years
    Wired, I was sure they would be installed with PHP7 from my command above. Maybe it's a temporary bug?
  • George Udosen
    George Udosen over 7 years
    Never assume any thing with computers or software, just double check to be sure.
  • Admin
    Admin over 7 years
    Thumbed up! Adding a soft shortlink solved it.
  • George Udosen
    George Udosen over 7 years
    @Benia AFAIK doing sudo a2enmod module_name actually does the same thing as ln -s /etc/php7/conf.d/module.ini /etc/php/7.0/mods-available/module.ini. So simple doing a2enmod will create that symbolic link for you.
  • Admin
    Admin over 7 years
    Reposting: Looking back, creating symlinks as in Arduino_sentinel's answer is not enough and I first need to install these, as in George's answer. Both answers are correct.
  • Admin
    Admin over 7 years
    George, I'll check this asap.
  • George Udosen
    George Udosen over 7 years
    You may also check in /etc/php7/apache2/conf.d, similar to /etc/php7/conf.d/ depending on your system.
  • Admin
    Admin over 7 years
    Wired, I've installed a new server environment from a script but now either a2enmod or ln -s works... Yet when I try to reinstall I get (for example): php7.0-mcrypt is already the newest version (7.0.8-0ubuntu0.16.04.3). 0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded. ... I just tried to upgrade and it didn't help --- Both methods still don't work. Moreover, after upgrading I get update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults.
  • George Udosen
    George Udosen over 7 years
    How do you know its not working ? It says already newest version hence its there already. The update-rc.d is for the old Upstart system, you should be using systemd in Ubuntu 16.04. Hence if you want to say reload apache2 you would do sudo systemctl restart apache2 rather than sudo service apache2 restart
  • George Udosen
    George Udosen over 7 years
  • Admin
    Admin over 7 years
    I was wrong. The links are created, but still ERROR: Module mbstring does not exist!. ERROR: Module mcrypt does not exist!.
  • George Udosen
    George Udosen over 7 years
    If you receive this comment respond found a solution.
  • Admin
    Admin over 7 years
    Sure, entering to chat.
  • Admin
    Admin over 7 years
    Replied there now.
  • Abhishek Pachal
    Abhishek Pachal over 3 years
    this solution worked for me