I've been developing a component, and have been trying to find some information, to no avail, of having my component perform a check of the PHP version before install. If PHP is greater than 7, then install. But, if PHP is less than 7 (such as 5.6) then show an error that PHP 7 is required, then stop the install.

I already figure that this will go into script.php in the preflight, but I'm struggling trying to find something to use to do the check.

Any suggestions?

1 Answer 1


Lots of components have a check like that. Here's the top of admin tools core install script eg.

protected $minimumPHPVersion = '5.3.3';

public function preflight($type, $parent)
        // Check the minimum PHP version
        if (!version_compare(PHP_VERSION, $this->minimumPHPVersion, 'ge'))
            $msg = "<p>You need PHP $this->minimumPHPVersion or later to install this package</p>";
            JLog::add($msg, JLog::WARNING, 'jerror');

            return false;

As you can see its using both the core constant for the version, and the core function for version comparison.

Further reading:

PHP Doc re the existance of constant PHP_VERSION

PHP Doc on using version compare

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.