Over the past couple of years I have had to set up several LAMP boxes from scratch to run Magento. Up until today I’ve had a script I could run that would tell me if all of the requirements are met to run Magento on the box. That script used phpversion() function for version comparison and now that function doesn’t seem to be working as it used to. A little Googling brought me to the answer that the function can be replaced with a PHP constant “PHP_VERSION”. I have provided my new working script for your perusal. I hope this is valid code for you guys for at least 6 months…

<?php
extension_check(array(
    'curl',
    'dom',
    'gd',
    'hash',
    'iconv',
    'mcrypt',
    'pcre',
    'pdo',
    'pdo_mysql',
    'simplexml'
));
 
function extension_check($extensions) {
    $fail = '';
   
    if(version_compare(PHP_VERSION, '5.2.0', '<')) {
        $fail .= '<li>PHP 5.2.0 (or greater)</li>';
    }
   
    if(!ini_get('safe_mode')) {
        if(preg_match('/[0-9].[0-9]+.[0-9]+/', shell_exec('mysql -V'), $version)) {
            if(version_compare($version[0], '4.1.20', '<')) {
                $fail .= '<li>MySQL 4.1.20 (or greater)</li>';
            }
        }
    }
   
    foreach($extensions as $extension) {
        if(!extension_loaded($extension)) {
            $fail .= '<li>'.$extension.'</li>';
        }
    }
   
    if($fail) {
        echo '<p>Your server does not meet the requirements for Magento.';
        echo 'The following requirements failed:</p>';
        echo '<ul>'.$fail.'</ul>';
    } else {
        echo '<p>Congratulations! Your server meets the requirements for Magento.</p>';
    }
}
?>