You need to login to send post. No account yet? Create one:
Create account

Drupal hosting - check Drupal requirements by PHP script

No replies
admin

Before you can proceed any web design, you need choose web hosting. This task is not as easy as it looks like, while modern CMS systems have many specific requirements. Fortunately almost all of web hosting providers offer free testing period during which you can check it.

One way how test web hosting is install your application, but that needs a lot of time and application has to be done. But what if is not?

Attached PHP script is dedicated to make your web development easier, if you are planning use CMS Drupal: simply create file drhostchck.php in root directory of your hosting, paste script shown below into this file, change variables $db_host, $db_pass & $db_user according to your web hosting database setting and open it in your web browser as http://YOURDOMAIN.COM/drhostchck.php. In clearly arranged table you'll see if choosen web hosting fits Drupal's requirements or not.

Entreaty: It'd be REALLY appreciate, if you'd keep this script on choosen hosting permanently and send me link to it here. On another page of this forum is list of hostings tested so far, which shall be as useful for everyone as complete it will be. As reward you'll get do follow link from that page! (There you can also see how this script working).

  1. <?php
  2. /*
  3.  * Script for testing if choosen webhosting meet Drupal 5.0 - 7.0 system requirements.
  4.  * Copyright (c) 2011 by http://www.seo-web-design-aberdeen.co.uk
  5.  */
  6. ?>
  7.  
  8.  
  9. <style>
  10. body, td {font-family: sans-serif;}
  11. table {border-collapse: collapse;margin-left: auto; margin-right: auto; text-align: left;width:400px;}
  12. td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
  13. .e {background-color: #ccccff; font-weight: bold; color: #000000;}
  14. .h {background-color: #9999cc; font-weight: bold; color: #000000;font-size: 120%;text-align:center;}
  15. .ok {background-color: #87c187; color: #000000;text-align:center;}
  16. .issue {background-color: #f85454;}
  17. .warning {background-color: #edc37b;}
  18. .f {width:10%;}
  19. </style>
  20. <title>Drupal hosting check</title>
  21.  
  22. <table>
  23. <td class="h">Drupal hosting check</td>
  24. </table>
  25.  
  26. <?php
  27.  
  28. /*
  29.  * MySQL account - set up this variables to fit your setting. You will likely need setup database and database user account in your hosting control panel.
  30.  */
  31.  
  32. $db_host = 'localhost';
  33. $db_pass = 'YOUR_DB_PASS';
  34. $db_user = 'YOUR_USER_NAME';
  35.  
  36. /*
  37.  * Common variables
  38.  */
  39.  
  40. print '<table>';
  41. $results['drupal_5']['name'] = "Drupal 5.x";
  42. $results['drupal_6']['name'] = "Drupal 6.x";
  43. $results['drupal_7']['name'] = "Drupal 7.x";
  44.  
  45. /*
  46.  * Check PHP maximum execution time
  47.  */
  48.  
  49. $exectime = ini_get('max_execution_time');
  50. $seconds = $exectime % 60;
  51. print '<tr><td class="e">PHP max execution time</td>';
  52. if ($exectime < 60) {
  53. print "<td>" . $exectime . "seconds." . "</td></tr>";
  54. if ($exectime < 30) {
  55. $results['drupal_5']['content']['exectime']['value'] = $results['drupal_6']['content']['exectime']['value'] = $results['drupal_7']['content']['exectime']['value'] = "PHP max execution time is insufficient. Many admin scripts will need more. Ask your provider for increase or change hosting.";
  56. $results['drupal_5']['content']['exectime']['flag'] = $results['drupal_6']['content']['exectime']['flag'] = $results['drupal_7']['content']['exectime']['flag'] = "issue";
  57. } else {
  58. $results['drupal_5']['content']['exectime']['value'] = $results['drupal_6']['content']['exectime']['value'] = $results['drupal_7']['content']['exectime']['value'] = "PHP max execution time is so-so useful. Simple website will work fine, but for complex sites you should ask your hosting for increase.";
  59. $results['drupal_5']['content']['exectime']['flag'] = $results['drupal_6']['content']['exectime']['flag'] = $results['drupal_7']['content']['exectime']['flag'] = "warning";
  60. }
  61. } else {
  62. printf ("<td>%d minutes %d seconds</td></tr>", $exectime / 60, $seconds);
  63. }
  64.  
  65. /*
  66.  * Check PHP memory limit
  67.  */
  68.  
  69. preg_match('/^[0-9]*/',ini_get('memory_limit'),$memlimit);
  70. if ($memlimit[0] < 16) {
  71. $results['drupal_5']['content']['memlimit']['value'] = $results['drupal_6']['content']['memlimit']['value'] = $results['drupal_7']['content']['memlimit']['value'] = "PHP memory limit is insufficient. Ask your provider for increase or change hosting.";
  72. $results['drupal_5']['content']['memlimit']['flag'] = $results['drupal_6']['content']['memlimit']['flag'] = $results['drupal_7']['content']['memlimit']['flag'] = "issue";
  73. } elseif ($memlimit[0] < 32) {
  74. $results['drupal_7']['content']['memlimit']['value'] = "PHP memory limit is insufficient. Ask your provider for increase or change hosting.";
  75. $results['drupal_7']['content']['memlimit']['flag'] = "issue";
  76. } elseif ($memlimit[0] < 96) {
  77. $results['drupal_5']['content']['memlimit']['value'] = $results['drupal_6']['content']['memlimit']['value'] = $results['drupal_7']['content']['memlimit']['value'] = "PHP memory limit is so-so useful. Basic Drupal website will work fine, but complex site with views will need more. Ask your hosting for increasing to at least 96M.";
  78. $results['drupal_5']['content']['memlimit']['flag'] = $results['drupal_6']['content']['memlimit']['flag'] = $results['drupal_7']['content']['memlimit']['flag'] = "warning";
  79. }
  80. print '<tr><td class="e">PHP memory limit</td><td>' . $memlimit[0] . "M</td></tr>";
  81.  
  82. /*
  83.  * Check MySQL extension
  84.  */
  85.  
  86.  
  87. print (function_exists('mysqli_connect')) ? '<tr><td class="e">MySQLi connector</td><td>Presented</td></tr>' : '<tr><td class="e">MySQLi connector</td><td>Missing</td></tr>';
  88. print (function_exists('mysql_connect')) ? '<tr><td class="e">MySQL connector</td><td>Presented</td></tr>' : '<tr><td class="e">MySQL connector</td><td>Missing</td></tr>';
  89. if (!function_exists('mysqli_connect') && !function_exists('mysql_connect')) {
  90. $results['drupal_5']['content']['mysqlconnector']['value'] = $results['drupal_6']['content']['mysqlconnector']['value'] = $results['drupal_7']['content']['mysqlconnector']['value'] = "MySQL connector is missing, As MySQL is the best supported database for Drupal, you should change hosting.";
  91. $results['drupal_5']['content']['mysqlconnector']['flag'] = $results['drupal_6']['content']['mysqlconnector']['flag'] = $results['drupal_7']['content']['mysqlconnector']['flag'] = "issue";
  92. }
  93.  
  94. /*
  95.  * Check GD library
  96.  */
  97.  
  98. if (function_exists("gd_info")) {
  99. print '<tr><td class="e">GD library</td><td>Presented</td></tr>';
  100. } else {
  101. $results['drupal_5']['content']['gd']['value'] = $results['drupal_6']['content']['gd']['value'] = $results['drupal_7']['content']['gd']['value'] = "GD library is not presented. Ask your hosting provider for upload it or find another hosting.";
  102. $results['drupal_5']['content']['gd']['flag'] = $results['drupal_6']['content']['gd']['flag'] = $results['drupal_7']['content']['gd']['flag'] = "issue";
  103. print '<tr><td class="e">GD library</td><td>Not presented</td></tr>';
  104. }
  105.  
  106. /*
  107.  * Check if session Autostart is off
  108.  */
  109.  
  110. if (!ini_get('session.auto_start')) {
  111. print '<tr><td class="e">Session Autostart</td><td>Off</td></tr>';
  112. } else {
  113. print '<tr><td class="e">Session Autostart</td><td>On</td></tr>';
  114. $results['drupal_5']['content']['autostart']['value'] = $results['drupal_6']['content']['autostart']['value'] = $results['drupal_7']['content']['autostart']['value'] = "PHP Session Autostart is on. Ask your provider to set it off.";
  115. $results['drupal_5']['content']['autostart']['flag'] = $results['drupal_6']['content']['autostart']['flag'] = $results['drupal_7']['content']['autostart']['flag'] = "issue";
  116. }
  117.  
  118. /*
  119.  * Check if PHP safe mode is off
  120.  */
  121.  
  122. if (!ini_get('safe_mode')) {
  123. print '<tr><td class="e">PHP Safe Mode</td><td>Off</td></tr>';
  124. } else {
  125. print '<tr><td class="e">PHP Safe Mode</td><td>On</td></tr>';
  126. $results['drupal_5']['content']['safemode']['value'] = $results['drupal_6']['content']['safemode']['value'] = $results['drupal_7']['content']['safemode']['value'] = "PHP Safe Mode is on. Ask your provider to set it off.";
  127. $results['drupal_5']['content']['safemode']['flag'] = $results['drupal_6']['content']['safemode']['flag'] = $results['drupal_7']['content']['safemode']['flag'] = "issue";
  128. }
  129.  
  130. /*
  131.  * Check PDO
  132.  */
  133.  
  134. if (extension_loaded ('PDO')) {
  135. print '<tr><td class="e">PDO extension</td><td>Loaded</td></tr>';
  136. } else {
  137. $results['drupal_7']['content']['pdo']['value'] = "PHP PDO is not loaded.";
  138. $results['drupal_7']['content']['pdo']['flag'] = "issue";
  139. print '<tr><td class="e">PDO extension</td><td>Not loaded</td></tr>';
  140. }
  141.  
  142. /*
  143.  * Check PHP version
  144.  */
  145.  
  146. $phpver = phpversion();
  147. if (version_compare($phpver,'4.4.0') === -1) {
  148. $results['drupal_5']['content']['phpver']['value'] = $results['drupal_6']['content']['phpver']['value'] = $results['drupal_7']['content']['phpver']['value'] = "PHP version is too low. Ask your hosting provider for upgrade to version 5.2.5.";
  149. $results['drupal_5']['content']['phpver']['flag'] = $results['drupal_6']['content']['phpver']['flag'] = $results['drupal_7']['content']['phpver']['flag'] = "issue";
  150. } elseif (version_compare($phpver,'5.2.5') === -1) {
  151. $results['drupal_7']['content']['phpver']['value'] = "PHP version is too low. Ask your hosting provider for upgrade to version 5.2.5 or more.";
  152. $results['drupal_7']['content']['phpver']['flag'] = "issue";
  153. } elseif (version_compare($phpver,'5.3') >= 0) {
  154. $results['drupal_5']['content']['phpver']['value'] = $results['drupal_6']['content']['phpver']['value'] = "PHP version is too high. Ask your hosting provider for downgrade to version 5.2.5.";
  155. $results['drupal_5']['content']['phpver']['flag'] = $results['drupal_6']['content']['phpver']['flag'] = "issue";
  156. }
  157. print '<tr><td class="e">PHP version</td><td>' . $phpver . '</td></tr>';
  158.  
  159. /*
  160.  * Check if Register globals is off
  161.  */
  162.  
  163. if (!ini_get('register_globals')) {
  164. print '<tr><td class="e">PHP Register Globals</td><td>Off</td></tr>';
  165. } else {
  166. print '<tr><td class="e">PHP Register Globals</td><td>On</td></tr>';
  167. $results['drupal_5']['content']['reglob']['value'] = $results['drupal_6']['content']['reglob']['value'] = $results['drupal_7']['content']['reglob']['value'] = "PHP Register Globals is on. Ask your provider to set it off.";
  168. $results['drupal_5']['content']['reglob']['flag'] = $results['drupal_6']['content']['reglob']['flag'] = $results['drupal_7']['content']['reglob']['flag'] = "issue";
  169. }
  170.  
  171. /*
  172.  * Check XML extension
  173.  */
  174.  
  175. if (class_exists('DOMDocument')) {
  176. print '<tr><td class="e">XML extension</td><td>Enabled</td></tr>';
  177. } else {
  178. print '<tr><td class="e">XML extension</td><td>Disabled</td></tr>';
  179. $results['drupal_5']['content']['xml']['value'] = $results['drupal_6']['content']['xml']['value'] = $results['drupal_7']['content']['xml']['value'] = "XML extension is disabled. Ask your hosting provider for enabling or change hosting.";
  180. $results['drupal_5']['content']['xml']['flag'] = $results['drupal_6']['content']['xml']['flag'] = $results['drupal_7']['content']['xml']['flag'] = "issue";
  181. }
  182.  
  183. /*
  184.  * Check Mod_rewrite
  185.  */
  186.  
  187. if (function_exists('apache_get_modules')) {
  188. if (in_array('mod_rewrite',apache_get_modules())) {
  189. print '<tr><td class="e">Apache mod_rewrite</td><td>Enabled</td></tr>';
  190. } else {
  191. $results['drupal_5']['content']['modrewrite']['value'] = $results['drupal_6']['content']['modrewrite']['value'] = $results['drupal_7']['content']['modrewrite']['value'] = "Apache mod_rewrite is disabled. Ask your hosting provider for enabling or change hosting.";
  192. $results['drupal_5']['content']['modrewrite']['flag'] = $results['drupal_6']['content']['modrewrite']['flag'] = $results['drupal_7']['content']['modrewrite']['flag'] = "issue";
  193. print '<tr><td class="e">Apache mod_rewrite</td><td>Disabled</td></tr>';
  194. }
  195. }
  196.  
  197. /*
  198.  * Check MySQL setting
  199.  */
  200.  
  201. if (@mysql_connect($db_host, $db_user, $db_pass)) {
  202.  
  203. // Max allowed packet check
  204. $result = mysql_query("SHOW VARIABLES LIKE 'max_allowed_packet'");
  205. $row = mysql_fetch_assoc($result);
  206. $max_allpacket = $row['Value'] / 1048576;
  207. if ($max_allpacket < 16) {
  208. $results['drupal_5']['content']['ma_packet']['value'] = $results['drupal_6']['content']['ma_packet']['value'] = $results['drupal_7']['content']['ma_packet']['value'] = "Max Allowed Packet in MySQL is too low. Ask your hosting provider to increase it to at least 16M.";
  209. $results['drupal_5']['content']['ma_packet']['flag'] = $results['drupal_6']['content']['ma_packet']['flag'] = $results['drupal_7']['content']['ma_packet']['flag'] = "issue";
  210. }
  211. printf ('<tr><td class="e">MySQL Max allowed packet</td><td>%d MB</td></tr>', $max_allpacket);
  212.  
  213. // Check MySQL version
  214. $result = mysql_query("SELECT VERSION()");
  215. $row = mysql_fetch_assoc($result);
  216. preg_match('/^[0-9.]*/',$row['VERSION()'],$result);
  217. $result = $result[0];
  218.  
  219. if (version_compare($result,'3.23.17') === -1) {
  220. $results['drupal_5']['content']['mysql_version']['value'] = $results['drupal_6']['content']['mysql_version']['value'] = $results['drupal_7']['content']['mysql_version']['value'] = "Installed MySQL is too old.";
  221. $results['drupal_5']['content']['mysql_version']['flag'] = $results['drupal_6']['content']['mysql_version']['flag'] = $results['drupal_7']['content']['mysql_version']['flag'] = "issue";
  222. } elseif (version_compare($result,'4.1') === -1) {
  223. $results['drupal_6']['content']['mysql_version']['value'] = $results['drupal_7']['content']['mysql_version']['value'] = "Installed MySQL is too old.";
  224. $results['drupal_6']['content']['mysql_version']['flag'] = $results['drupal_7']['content']['mysql_version']['flag'] = "issue";
  225. } elseif (version_compare($result,'5.0.15') === -1) {
  226. $results['drupal_7']['content']['mysql_version']['value'] = "Installed MySQL is too old.";
  227. $results['drupal_7']['content']['mysql_version']['flag'] = "issue";
  228. }
  229. print '<tr><td class="e">MySQL version</td><td>' . $result . '</td></tr>';
  230. } elseif (is_null($results['drupal_5']['content']['mysqlconnector'])) {
  231. $results['drupal_5']['content']['mysql_version']['value'] = $results['drupal_6']['content']['mysql_version']['value'] = $results['drupal_7']['content']['mysql_version']['value'] = "Unable to connect MySQL server, check your account settings. This is likely your and not web hostings fault.";
  232. $results['drupal_5']['content']['mysql_version']['flag'] = $results['drupal_6']['content']['mysql_version']['flag'] = $results['drupal_7']['content']['mysql_version']['flag'] = "issue";
  233. }
  234. print "</table><br />";
  235.  
  236. foreach ($results as $drupal => $result) {
  237. print '<table>';
  238. print '<tr><td class="h">' . $result['name'] . '</td></tr>';
  239. if (is_null($result['content'])) {
  240. print '<tr><td class="ok">Your hosting seems to be OK for this version of Drupal.</td></tr></table><br />';
  241. } else {
  242. print '</table><table>';
  243. foreach ($result['content'] as $type => $values) {
  244. print '<tr class="' . $values['flag'] . '">';
  245. print ($values['flag'] == "issue") ? '<td class="f">!!!</td>' : '<td class="f">!</td>';
  246. print '<td>' . $values['value'] . '</td></tr>';
  247. }
  248. print '</table><br />';
  249. }
  250. }
  251. ?>
  252.  
  253. <p style="text-align:center;">Copyright (c) 2011 by <a href ="http://www.seo-web-design-aberdeen.co.uk">http://www.seo-web-design-aberdeen.co.uk</a></p>