Skip to content

Need detailed steps to install Mcrypt (1.0.6 or 1.0.7) for PHP8.2 on Amazon Linux 2023

0

I have a legacy application that is using PHP5.6 on an EC2 instance no longer supported. I am in the process of migrating the application to an Amazon Linux 2023 EC2 instance, with PHP8.2. I have not looked at this environment for years, and I need detailed steps to install mcrypt (1.0.6 or 1.0.7).

Alternatives to mcrypt are not viable - this is a legacy application with thousands of lines of code. I need mcrypt.

I see references to pecl and epel - not sure what or how to proceed. Any help is much appreciated.

Colin Goldberg

asked 2 years ago1.7K views
3 Answers
3

php-mcrypt requires libmcrypt and libmcrypt-devel

As per [Package Request] - libmcrypt, libmcrypt-devel #403 , AL2023 will not include them. This is also mentioned at Functionality deprecated in AL2 and removed in AL2023

The mcrypt library and associated PHP extension was deprecated in AL2, and is no longer present in AL2023.

Upstream PHP deprecated the mcrypt extension in PHP 7.1 which was first released in December 2016 and had its final release in October 2019.

The upstream mcrypt library last made a release in 2007 , and has not made the migration from cvs revision control that SourceForge required for new commits in 2017, with the most recent commit (and only for 3 years prior) being from 2011 removing the mention of the project having a maintainer.

Any remaining users of mcrypt are advised to port their code to OpenSSL, as mcrypt will not be added to AL2023. `

You will need to get libmcrypt from other sources and use pecl to compile.

This may work for you.

Create /etc/yum.repos.d/fedora.repo file with the following content. I am using Fedora 36 as AL2023 is based in part on it

[fedora]
name=Fedora 36 - $basearch
#baseurl=http://download.example/pub/fedora/linux/releases/36/Everything/$basearch/os/
metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-36&arch=$basearch
enabled=1
countme=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=0
gpgkey=https://getfedora.org/static/fedora.gpg
skip_if_unavailable=False

Install the mcrypt libaries from Fedora repo

sudo dnf clean all
sudo dnf install libmcrypt-devel libmcrypt -y

Disable Fedora repo

sudo dnf config-manager --disable fedora
sudo dnf clean all

To use pecl to compile php-mcrypt,

sudo dnf install -y php-devel php-pear gcc
sudo pecl update-channels
sudo pear config-set php_ini /etc/php.ini
sudo pecl install mcrypt

This is the phpinfo() output from my AL2023 Enter image description here

AWS
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
  • I get an error at this point:

    • dnf install -q -y php-devel php-pear gcc
    • Error: Problem: problem with installed package php8.2-cli-8.2.15-1.amzn2023.0.2.x86_64
    • package php8.2-cli-8.2.15-1.amzn2023.0.2.x86_64 from @System conflicts with php-cli < 8.2.0 provided by php-cli-8.1.4-1.fc36.x86_64 from fedora
    • package php8.2-cli-8.2.15-1.amzn2023.0.1.x86_64 from amazonlinux conflicts with php-cli < 8.2.0 provided by php-cli-8.1.4-1.fc36.x86_64 from fedora
    • package php8.2-cli-8.2.15-1.amzn2023.0.2.x86_64 from amazonlinux conflicts with php-cli < 8.2.0 provided by php-cli-8.1.4-1.fc36.x86_64 from fedora
    • package php8.2-cli-8.2.7-1.amzn2023.0.1.x86_64 from amazonlinux conflicts with php-cli < 8.2.0 provided by php-cli-8.1.4-1.fc36.x86_64 from fedora
    • package php8.2-cli-8.2.9-1.amzn2023.0.2.x86_64 from amazonlinux conflicts with php-cli < 8.2.0 provided by php-cli-8.1.4-1.fc36.x86_64 from fedora
    • package php8.2-cli-8.2.9-1.amzn2023.0.3.x86_64 from amazonlinux conflicts with php-cli < 8.2.0 provided by php-cli-8.1.4-1.fc36.x86_64 from fedora
    • package php-devel-8.1.4-1.fc36.x86_64 from fedora requires php-cli(x86-64) = 8.1.4-1.fc36, but none of the providers can be installed
    • conflicting requests

    I see from https://mirrormanager.fedoraproject.org/ that fedora 41 may be the latest, but I am not sure how to proceed. Is there a way to reverse the fedora.repo installation and start again?

  • My apologies for missing out the step to disable Fedora repo. I have updated my post. I suggest you try Fedora 36 first as above since AL2023 includes components from Fedora 34 to 36.

1

I had posted the following yesterday, before I saw the latest response. But I must have missed a step here, because my response (from yesterday) does not appear.

Here was my response: Update: After updating the fedora version in fedora.repo (to 38, 39, 40) - without success, I removed (renamed) fedora.repo and was able to successfully run "dnf -y php-devel" which appeared to be the main stumbling block. Also php-pear and gcc.

Then after the two pecl commands, it seemed to work.

[I was not able to reconcile the php extension versions with what was sourced from the fedora versions].

Thanks for your help.

answered 2 years ago
  • Great to know you resolved it. Thanks for the status update!

-1
  1. First, update your package repository and install any available updates.
sudo yum update -y
  1. Install necessary development tools and libraries.
sudo yum groupinstall -y "Development Tools"
sudo yum install -y php php-devel php-pear libmcrypt libmcrypt-devel
  1. The Extra Packages for Enterprise Linux (EPEL) repository contains additional packages that are not included in the default repositories.
sudo amazon-linux-extras install epel -y
  1. If PHP 8.2 is not already installed, install it using the Amazon Linux Extras repository.
sudo amazon-linux-extras enable php8.2
sudo yum clean metadata
sudo yum install -y php php-cli php-common php-devel php-pear
  1. Install PECL. PECL (PHP Extension Community Library) is used to install PHP extensions.
sudo yum install -y php-pear
  1. Use PECL to install the mcrypt extension. Specify the version you need (1.0.6 or 1.0.7).
sudo pecl install mcrypt-1.0.6

Alternatively, for version 1.0.7, use:

sudo pecl install mcrypt-1.0.7
  1. Enable the mcrypt Extension. After installing mcrypt, you need to enable it in your PHP configuration.
echo "extension=mcrypt.so" | sudo tee /etc/php.d/20-mcrypt.ini
  1. Restart your web server to apply the changes. If you are using Apache, use the following command:
sudo systemctl restart httpd

If you are using Nginx with PHP-FPM, use:

sudo systemctl restart php-fpm
sudo systemctl restart nginx

9.Verify Installation. To verify that mcrypt is installed and enabled, create a PHP info file or use the CLI to check.

php -m | grep mcrypt

Alternatively, create a phpinfo.php file in your web server's root directory with the following content:

<?php phpinfo(); ?>

Access this file via your web browser and search for "mcrypt" in the output to ensure it is enabled.

EXPERT
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.