I have split out the requirements api from my core installer effort. Unused functionality was removed for now. This patch allows modules to define their minimum requirements by adding a _requirements() hook to their .install file.
Core Drupal requirements are currently defined in system.install. Here are a few example requirements taken from the system.install file added by this patch:
<?php
// Verify version of PHP
$requirements['php']['version'] = array(
'minimum_version' => DRUPAL_MINIMUM_PHP,
'message' => t('Drupal requires PHP version %minimum_version or greater. You are using PHP version %installed_version.'),
'required' => TRUE
);
// Verify PHP memory limits
if (function_exists(memory_get_usage)) {
// memory_get_usage() will only be defined if PHP is compiled with
// the --enable-memory-limit configuration option.
$requirements['php']['memory_limit'] = array(
'value' => DRUPAL_MINIMUM_MEMORY,
'operator' => '>=',
'message' => t('Your PHP installation limits Drupal to using only %current_value of RAM. It is suggested that you modify the memory_limit directive to allow at least %value of RAM.'),
'shorthand' => TRUE
);
}
// %settings.php is a special case, Drupal will search for it...
$requirements['file']['%settings.php'] = array(
'type' => 'file',
'mask' => FILE_EXIST|FILE_READABLE|FILE_NOT_WRITEABLE,
'required' => TRUE,
'message' => t('Your <em>settings.php</em> file is currently writable by the web server process. This is security risk, it is advised that you make this file read only.')
);
?>
The patch also modifies the system module so that when visiting "adminster >> modules" the requirements of all enabled modules are verified. (This is helpful for detecting an accidental change to your environment from for example re-compiling PHP). Additionally, when an admin tries to enable new modules, the new module requirements (if any) are first verified and the module is not enabled if requirements are not met.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | requirements_0.patch | 33.59 KB | jeremy |
| #1 | module.png | 577.77 KB | jeremy |
| requirements.patch | 30.2 KB | jeremy |
Comments
Comment #1
jeremy commentedThe attached screen shot shows some messages generated when going to "administer >> modules" on a system that does not have mod_rewrite enabled, and does not have the PHP zlib extension enabled.
Comment #2
markus_petrux commented// TODO: how can we detect pgsql version pre-PHP5?
I already posted some code here that works. Well, the version numbers might need to be extracted using a regexp (the result might be a string with additional information). Note that, for MySQL, it is also necessary to try out "SELECT VERSION()", since mysql_get_server_info might not be there.
Comment #3
Cvbge commentedAbout postgresql version, I've written a function in http://drupal.org/node/29082#comment-43377 some time ago, that does similar things as yours, but returns version as comparable integer and does not use pg_version() at all, so yours might be better.
Comment #4
Amazon commentedCross posting to a list of the error messages for requirement checking APIs.
Please help in reviewing
http://drupal.org/node/51772
Comment #5
markus_petrux commentedRegarding safe_mode off requirement... is it really required?
Comment #6
markus_petrux commented_using_apache() function is not reliable. $_SERVER['SERVER_SOFTWARE'] may contain the word "apache", but apache_* functions are available only when PHP is running as an Apache module. apache_get_version() may fail. Sooner or later you would have to fix that. ;-)
Not sure how important it is to check for Apache version or modules, when Drupal can be installed on non-apache servers.
Maybe you could add code to check for PHP extensions using extension_loaded or get_loaded_extensions?
Comment #7
moshe weitzman commentedI love requirements checking. Does this checker assume that Drupal is up and working already? I'm hoping that it is like update.ph in that it works without a stovk settings.php - no DB connection. The most common use case IMO is "I just downloaded this drupal thing, is my site capable of running it?" What URL will this appear on?
Comment #8
jeremy commentedIn this other issue I have an installer implementation that utilizes this requirements API via a new install.php file (try out a pre-patched tarball of this functionality here). That's the ultimate goal, and will solve your "Does this Drupal thing run on my server?" question, but for now the focus is on getting the requirements API into and used by core. The patch attached to this issue is a subset of the installer, and only performs requirements checks on the "administer >> modules" page.
Comment #9
markus_petrux commentedJust suggestion, regarding version checking, hmm... let's say a contrib module works in PHP 4, but PHP 5 is not supported, yet. Or something that worked in (say) MySQL 3+ is now broken in MySQL 5, with no easy workaround, the contrib stuff might still be released with such "limitations"...
Actually, it is possible to specify a
minimum_version, but what if amaximum_versioncheck is required?Comment #10
jeremy commentedmysql_get_server_info() was added in PHP 4.0.5, while Drupal requires PHP 4.3.3 or greater. However, we do now detect if the function is missing so we can error gracefully.
No, it's not required, just recommended so that Drupal can do things like calling set_time_limit() to increase the length of time before a browser will time out. Thanks, I have changed it to a warning.
Thanks, I used code similar to your example.
Yes, it would be great to have alternative (yet reliable) methods of finding the Apache server version and if modules are enabled. For now we just first verify that the functions we need are available.
Any non-required applications are separated into their own requirements.*.inc files. For example, requirements.mysql.inc, requirements.pgsql.inc, and requirements.apache.inc. The additional requirements checks for these applications are only performed if we detect that they are actively being used. In the case of Apache, I believe it is very helpful to explain how mod_rewrite is required for Clean URLs.
Sure, this could be added easily enough.
Good point. However at this time it's not strictly required by core, and I'm focused on doing what I can to get this merged into core. That said, I agree it's important and might add the functionality in a future version of the patch.
Thanks for all the review and suggestions. A newly improved version of the patch is attached. In addition to the recommendations above, it also includes improved error messages provided by webchick.
Comment #11
moshe weitzman commentedthanks for the clarification, jeremy. also thanks to webchick and jeremy for the nice error emssages. i will try ot oreview this one soon.
Comment #12
markus_petrux commentedRegarding the comment about safe_mode... while, it may make things easier to avoid conflicts with file uploads et al, there are security issues involved. Changing safe_mode may not be an option as it cannot be changed in .htaccess files.
Instead of saying "it is recommended..." I would say something like "safe_mode is enabled, consider switching it off if you have problems with file uploads, but keep in mind safe_mode on is more secure. You might want to contact your hosting provider.". Yeah, I know it is not very well written, but I hope you get the idea. :-)
Comment #13
webchickGreat idea! There is an issue ready and waiting for someone to come in and clean up the error messages:
http://drupal.org/node/51772
Please post your feedback there, and try and tackle a few more while you're at it. ;)
Comment #14
markus_petrux commentedJeremy, a couple of E_NOTICES:
function_exists(version_compare) and function_exists(memory_get_usage)
Note the lack of (say) single quotes.
Comment #15
markus_petrux commentedAside from lack of single quotes... something wrong when checking for the PHP version?
If version_compare() does not exist, then that will return TRUE? However, if that happens, PHP version is lower than 4.1, hence it should return FALSE, or...?
Also, PHP (any version) is required, so maybe the check for
$version['required']could be removed?Comment #16
markus_petrux commentedSorry, disregard (part of) my previous comment. I guess I had a boolean parser error when looking at the code. :-?
Maybe this is still valid however?
Comment #17
dries commentedPlease use $error instead of $err.
Some strings can't be translated.
I'm a little bit shocked by the amount of code required to implement this. It's bigger than expected. drupal_verify_requirements_php() is a bit weird. I'm not yet convinced this is really needed, or whether this is the simplest approach. Looks a bit complicated.
I'm not a big fan of the "version guessing" (regex). It makes for ugly code.
$requirements_old["$new"] can be written as $requirements_old[$new].
Can format_size() be used instead of _shorthand_to_bytes()?
Comment #18
danielc commentedHere's some feedback regarding the way the database server version is determined in this issue's attachment "requirements_0.patch." You'll find code addressing these issues at the bottom of this post.
Won't it be good to give all Drupal components access to this functionality? I encourage this aspect of the requirements checking be placed in a centralized location, like database.inc. Similarly, it would be more usable if there would be one function, perhaps called db_get_server_version(), rather than one function per DBMS.
Your code strips "alpha", "beta", etc, but that can be relevant. version_compare() is designed to handle such terms.
It would be nice if the function cached the result so the database doesn't need to be queried over and over each time the function is called.
I wouldn't even bother checking pg_version() at this point. It's PHP 5 only and PostgreSQL 7.4 only. But more importantly, it isn't reliable because the 'server_version' element is missing (at least PHP 5.1.2). So cut to the chase and do the SELECT VERSION().
mysql_get_server_info() also doesn't exist prior to MySQL 4.0.1-alpha. So, it'd be handy to provide a SELECT VERSION() fallback when necessary.
So, here's the code I suggest using:
Comment #19
moshe weitzman commentedwent in with a different issue
Comment #20
(not verified) commented