• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Script to check Server Configs

I am writing a PHP script to test that tests to make sure the server has the proper configs set for our software. There are a couple I'm not 100% sure how to test.

1. Make sure the server has mysql installed and available without specifying any settings.
2. Make sure the curl library is available

I need some code that determines these. All it needs to do is say passed or failed.


Anyone got an example?

I was trying this that I found on PHP.net for the mysql but the shell_exec looks like a potential problem as it may be disabled on most servers.

function find_SQL_Version() {
   $output = shell_exec('mysql -V');
   preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
   return $version[0];
}

0
Isisagate
Asked:
Isisagate
  • 2
1 Solution
 
Aamir SaeedCommented:
0
 
IsisagateAuthor Commented:
phpinfo isn't what I am looking for... this is an attempt to write a script that a non-programmer business owner can upload and know that their hosting is sufficient to use the scripts. So it has to be minimal.
0
 
DrBrainiacCommented:
PHP trows a warning when a command is not found (when software is not installed or working) with the message "unknown command"

You could use a error handler to take care of this (little primitive, but should work though):


<?php
$mysql_exists = true;
$curl_exists = true;

// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline) {
  if(substr_count($errstr,"unknown command")) {
    if(substr_count($errstr,"mysql_connect")) {
      $GLOBALS['mysql_exists'] = false;
    }elseif(substr_count($errstr,"curl_version")){
      $GLOBALS['curl_exists'] = false;
    }
  }
  //echo "<b>WARNING</b> [$errno] $errstr<br />\n";
  return true;
}

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

// just run the commands and let the error handler take care of the rest
$dbcon = mysql_connect();
$curl = curl_version();

// output results
echo $mysql_exists ? "mysql enabled<br />" : "mysql disabled<br />";
echo $curl_exists ? "curl enabled<br />" : "curl disabled<br />";
?>
0
 
DrBrainiacCommented:
Im sorry, now I test this myself i see it is a different message: "Call to undefined function"
So change "unknown command" to this and it should work
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now