My module depends on a PHP library (sites/all/libraries/xyz/xyz-library.php). I want drupal to continue with installation only if library requirements of my module are met.

I want something of this kind, in my mymodule.install:

function mymodule_install() {
  if( library_exists() )   return; //continue with installation
    drupal_set_message(t('Installation failed. Please put xyz-library.php in sites/all/libraries/xyz folder.'), 'error');
    return FALSE; // installation failed

2 Answers 2


You can do this in hook_requirements, from the documentation:

During the 'install' phase, modules can for example assert that library or server versions are available or sufficient. Note that the installation of a module can happen during installation of Drupal itself (by install.php) with an installation profile or later by hand. As a consequence, install-time requirements must be checked without access to the full Drupal API, because it is not available during install.php. For localization you should for example use $t = get_t() to retrieve the appropriate localization function name (t() or st()). If a requirement has a severity of REQUIREMENT_ERROR, install.php will abort or at least the module will not install. Other severity levels have no effect on the installation. Module dependencies do not belong to these installation requirements, but should be defined in the module's .info file.

After your check, you return array (see docs again) with REQUIREMENT_ERROR.

function example_requirements($phase) {
  $requirements = array();
  // Ensure translations do not break at install time
  $t = get_t();

  $requirements['example'] = array(
    'title' => $t('Example Library'),

  $libraries = libraries_get_libraries();
  if (isset($libraries['example'])) {
    $requirements['example']['value'] = $t('Installed');
    $requirements['example']['severity'] = REQUIREMENT_OK;
  else {
    $requirements['example']['value'] = $t('Not Installed');
    $requirements['example']['severity'] = REQUIREMENT_ERROR;
    $requirements['example']['description'] = $t('Please install the example library %url.', array('%url' => 'http://example.com'));

  return $requirements;

You can check this code example here.


Sounds like you're looking for hook_requirements(), which will abort the installation if the requirements are not met.

So if your module was named mymodule, you'd create a function called mymodule_requirements() inside the file mymodule.install.

Your Answer

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

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