Script to check Server Configs

Posted on 2007-08-01
Last Modified: 2013-12-12
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 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];

Question by:Isisagate
    LVL 14

    Expert Comment

    by:Aamir Saeed
    LVL 11

    Author Comment

    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.
    LVL 4

    Accepted Solution

    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):

    $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;
          $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 />";
    LVL 4

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now