After downgrading from PHP 5.5 to PHP 5.4 on CentOS 6.5, the PECL command stops working completely. Instead of executing normally, it produces a cascade of errors including:
- Multiple "Invalid argument supplied for foreach()" warnings
- Numerous undefined index notices for various parameters
- Missing XML extension warnings
This typically happens when:
- The PEAR/PECL installation remains configured for PHP 5.5 while running under PHP 5.4
- The configuration files and environment variables weren't properly reset during the downgrade
- Some PHP extensions required by PECL (like XML) aren't properly enabled
1. Clean Up Previous Installations
First, completely remove all PHP and PEAR/PECL components:
sudo yum remove php55w php54w php-common pear
sudo rm -rf /usr/share/pear
sudo rm -rf /etc/php.d
2. Fresh Installation
Install PHP 5.4 with required extensions:
sudo yum install php54w php54w-common php54w-devel php54w-pear php54w-xml
sudo pecl channel-update pecl.php.net
3. Rebuild PECL
Force a complete rebuild of PECL:
sudo pear upgrade --force PEAR
sudo pecl clear-cache
4. Verify PHP Configuration
Check if XML extension is properly loaded:
php -m | grep xml
If not found, enable it:
sudo yum install php54w-xml
sudo service httpd restart
5. Test PECL Installation
Try installing a simple extension to verify:
sudo pecl install APCu
If the above doesn't work, consider this nuclear option:
sudo rpm -e --nodeps php-pear
sudo yum clean all
sudo yum install php54w-pear
Then reconfigure PEAR:
sudo pear config-set php_ini /etc/php.ini
sudo pear update-channels
For future PHP version changes:
- Always back up PEAR configuration:
pear config-show > pear_backup.conf
- Remove all PECL extensions before downgrading
- Consider using phpbrew for easier version management
After downgrading from PHP 5.5 to 5.4 on CentOS 6.5, the PECL command starts throwing multiple warnings and notices. The core issues appear to be:
Warning: Invalid argument supplied for foreach() in Command.php
Notice: Undefined index in Role.php (multiple occurrences)
XML Extension not found
This typically happens when:
- PEAR/PECL installation was originally done with PHP 5.5
- System paths and configurations weren't properly cleaned during downgrade
- XML extension became unavailable after downgrade
- Package registry got corrupted during version switching
1. Clean Up Existing Installations
First remove all PHP-related packages completely:
sudo yum remove php54w php55w php-common
sudo rm -rf /usr/share/pear
sudo rm -rf /etc/php.d
2. Reinstall PHP 5.4 with Required Extensions
sudo yum install php54w php54w-common php54w-devel php54w-pear php54w-xml
sudo pecl channel-update pecl.php.net
3. Reinitialize PEAR/PECL
Force reinstall the base system:
sudo pear install -a -f PEAR
sudo pecl update-channels
4. Verify XML Extension
Create a test file (xml_test.php):
<?php
phpinfo();
?>
Run it and verify XML appears in the modules section.
5. Registry Repair (If Needed)
For persistent issues, try rebuilding the registry:
sudo pear clear-cache
sudo rm -f /tmp/pear/cache/*
sudo pear rebuild-db
If the above doesn't work, consider installing from source:
wget http://pear.php.net/go-pear.phar
sudo php go-pear.phar
Then follow the interactive installer prompts.
- Always use version-specific pear/pecl binaries (e.g., /usr/bin/pear5.4)
- Maintain separate pear directories for different PHP versions
- Consider using phpbrew for multi-version management