I have updated cli and nginx to use php 7.2 using the follow commands:
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev
sudo pecl install mcrypt-1.0.1
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20190902/mcrypt > /etc/php/7.2/mods-available/mcrypt.ini"
However when I run:
php -i | grep "mcrypt"
I get the following response:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20190902/mcrypt' (tried: /usr/lib/php/20190902/mcrypt (/usr/lib/php/20190902/mcrypt: cannot open shared object file: No such file or directory), /usr/lib/php/20170718//usr/lib/php/20190902/mcrypt.so (/usr/lib/php/20170718//usr/lib/php/20190902/mcrypt.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
/etc/php/7.2/cli/conf.d/mcrypt.ini
phpinfo() doesn’t display mcrypt info either, I’m guessing for the same reason.
I’ve tried changing the path in /etc/php/7.2/cli/php.ini; ‘extension_dir’ is actually commented out, but if I uncomment it, whatever I update it to, it gets appended to ‘/usr/lib/php/20170718/’.
Why does my system insist on using ‘/usr/lib/php/20170718/’ as the path?
How do I get mcrypt working for cli and nginx?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello, @ecell100
As you can see from the warning message, the problem is with the actual path of the library:
(/usr/lib/php/20190902/mcrypt: cannot open shared object file: No such file or directory), /usr/lib/php/20170718//usr/lib/php/20190902/mcrypt.so (/usr/lib/php/20170718//usr/lib/php/20190902/mcrypt.so: cannot open shared object file: No such file or directory)) in Unknown on line
You can either try running these two commands:
sudo bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"
or change the path manually by editing the ini files directly. You can then again test if everything is loaded correctly:
php -i | grep "mcrypt"
Keep in mind that you need to restart Nginx as well in order to make sure the new library is loaded.
Let me know how it goes.
Regards, Alex
HEY I FOUND A SOLUTION firstly Goto /etc/php/7.2/cli/conf.d and /etc/php/7.2/cgi/conf.d and /etc/php/7.2/mods-available and /etc/php/7.2/apache2/conf.d and remove mcrypt.ini from all those folder.And back up mcrypt.ini if u need
this is beacause php 7.2 dosent depend on it
Hey @danielzhang,
The mcrypt library was deprecated in PHP 7.1, and it was removed entirely in PHP 7.2. If you’re using PHP 7.3 or a later version, you can’t enable mcrypt in the same way as before. Instead, you’ll need to use a different method.
However, if you still need to use mcrypt due to some legacy code that you can’t update to use a more modern encryption method, there’s a PECL extension available that brings back mcrypt to PHP 7.3 or later versions.
In this example, we’ll be using 8.1
Install prerequisites
Before you install the mcrypt extension, you’ll need to make sure that you have some necessary packages installed on your system.
On Ubuntu:
- sudo apt-get update
- sudo apt-get install php-pear php8.1-dev gcc make autoconf libc-dev pkg-config libmcrypt-dev php-pear
On CentOS:
- sudo yum install php-pear php-devel gcc make autoconf libc-dev pkg-config libmcrypt-devel php-pear
Install mcrypt extension
After you’ve installed these packages, you can install the mcrypt extension itself:
- sudo pecl install mcrypt-1.0.3
During the installation, you may be asked for the libmcrypt prefix. If you are, press enter to skip.
Configure PHP to use the mcrypt extension
After the installation is complete, you’ll need to tell PHP to use the mcrypt extension. To do this, you’ll need to modify your php.ini file.
First, you’ll need to find it. You can do this by using the following command:
- php --ini
Look for the line that says “Loaded Configuration File”. This will tell you where your php.ini file is located.
Open this file with your favorite text editor (like nano or vim). For example:
- sudo nano /etc/php/8.1/cli/php.ini
Add the following line to the file:
- extension=mcrypt.so
Restart your web server
Finally, you’ll need to restart your web server for the changes to take effect.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.