When working with PHP on macOS, it's common to encounter version conflicts between the CLI and web server environments. The error message:
The requested PHP extension ext-mcrypt * is missing from your system
typically indicates one of three scenarios:
- Mcrypt extension isn't properly installed
- PHP versions differ between CLI and web server
- Extension isn't enabled in the correct php.ini file
First, let's verify the PHP versions in different environments:
# Check CLI version
php -v
# Check web server version (create a test.php file with phpinfo())
In your case, you're seeing:
- CLI: PHP 5.4.12
- Web: PHP 5.3.15
For modern macOS systems, the best approach is using Homebrew:
brew install autoconf
brew install mcrypt
brew install php@5.4 --with-mcrypt
To resolve the version mismatch, we need to ensure both environments use the same PHP installation:
# Link the correct PHP version
brew unlink php
brew link php@5.4 --force
# Update Apache configuration
sudo nano /etc/apache2/httpd.conf
# Ensure this line points to your Homebrew PHP:
LoadModule php5_module /usr/local/opt/php@5.4/libexec/apache2/libphp5.so
After installation, verify mcrypt is properly loaded:
php -i | grep mcrypt
# Should return:
mcrypt support => enabled
mcrypt_filter support => enabled
If Homebrew installation fails, try manual compilation:
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
sudo make install
Ensure your php.ini files are consistent:
# Locate all php.ini files
php --ini | grep "Loaded Configuration File"
php -i | grep "Additional .ini files"
Add or uncomment this line in all relevant php.ini files:
extension=mcrypt.so
Many developers encounter the frustrating error The requested PHP extension ext-mcrypt * is missing from your system
despite having mcrypt seemingly installed. The root cause typically stems from version mismatches between CLI and web server PHP environments.
First, verify your PHP versions across different environments:
# Check CLI PHP version
php -v
# Check web server PHP version (create phpinfo.php)
<?php phpinfo(); ?>
In your case, the terminal reports PHP 5.4.12 while phpinfo() shows 5.3.15 - this explains why mcrypt appears installed but isn't recognized by Composer.
Method 1: Aligning PHP Versions
Force your system to use the same PHP version everywhere:
# For Homebrew users
brew unlink php && brew link php@5.4 --force
# Update PATH in your shell config
echo 'export PATH="/usr/local/opt/php@5.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@5.4/sbin:$PATH"' >> ~/.zshrc
Method 2: Installing mcrypt Properly
# For Homebrew PHP installations
brew install mcrypt php54-mcrypt
# Alternative compilation method
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && sudo make install
After installation, verify mcrypt appears in both environments:
# CLI check
php -m | grep mcrypt
# Web server check
Create a phpinfo.php file containing:
<?php
if (extension_loaded('mcrypt')) {
echo 'mcrypt is loaded';
} else {
echo 'mcrypt NOT loaded';
}
?>
If the issue persists only during composer install
, try:
composer config -g platform.php 5.4.12
composer install --ignore-platform-reqs