How Tos > Remote

Confirm your remote PHP settings

On your remote document root, create a directory called “.test”.

Inside of this .test directory create a subdirectory called “scripts”.

Inside of the “scripts directory add the php script “check.php

When you have made this file, in the _USER_EDITABLE_SECTION_, fill in correct values for $serverType, $liveUrlString, $db_server, $db_name.

<?php

/*
   *   INSTRUCTIONS
   *   1) Edit this file with your remote server credentials inside the "USER_EDITABLE_SECTION"
   *   2) On your remote document root, create a directory called: ".test"
   *   3) Inside ".test" directory, create another directory called: "scripts"
   *   4) Inside "scripts" directory, add the php script: "check.php"
*/

  /*******************_USER_EDITABLE_SECTION_STARTED_*******************/

  $serverType = 'apache';
  $liveUrlString = ''; // DO NOT add the '/' at the end of your url string. This is what you have to enter in a webbrowser to display your remote website. 
  $db_server = ''; // SQL server address. You can find this information inside wp-config.php of your WordPress site.
  $db_name = ''; // SQL database your WordPress site uses. You can find this information inside wp-config.php of your WordPress site.
  $db_username = ''; // SQL user access. You can find this information inside wp-config.php of your WordPress site.
  $db_password = ''; // SQL password access. You can find this information inside wp-config.php of your WordPress site.

  /*******************_USER_EDITABLE_SECTION_ENDED_*******************/
  
  
  foreach ($_REQUEST as $key => $val) { $val = urldecode($val); $_REQUEST[$key] = $val; }
  if (isset($_REQUEST["phpversion"])) {
    echo "Checking remote server setup has started...<br>";
    echo "-------------------------------<br>";
    $canRunServerResult = canRunServer($serverType)["result"];
    echo "Can run server: ".($canRunServerResult == 0 ? 'Yes' : 'Error: '.$canRunServerResult.'')."<br>";
    echo "-------------------------------<br>";
    $canWriteFilesResult = canWriteFiles()["result"];
    echo "Can write files: ".($canWriteFilesResult == 0 ? 'Yes' : 'Error: '.$canWriteFilesResult.'')."<br>";
    echo "-------------------------------<br>";
    $hasEnoughFreeDiskspaceForDownloadResult = hasEnoughFreeDiskspaceForDownload("../../.");
    echo "Has enough disk space: ".($hasEnoughFreeDiskspaceForDownloadResult == 0 ? 'Yes' : 'Error: '.$hasEnoughFreeDiskspaceForDownloadResult.'')."<br>";
    echo "-------------------------------<br>";
    echo "Remote host type: ".getHostTypeAtPath("../../")."<br>";
    echo "-------------------------------<br>";
    echo "Remote document root size: ".getDirectorySize("../../.")."<br>";
    echo "-------------------------------<br>";
    echo "Remote PHP version: ".$_REQUEST["phpversion"]."<br>";
    echo "-------------------------------<br>";
    $tempArrayCanRunSqlFile = canRunSqlFile($db_server, $db_name, $db_username, $db_password);
    echo "Remote MySQL version: ".$tempArrayCanRunSqlFile["remoteMySQLVersion"]."; Result: ".$tempArrayCanRunSqlFile["result"]."<br>";    
  
  } else {
    echo runCurl($liveUrlString.'/.test/scripts/check.php');
    echo "-------------------------------<br>";
    echo "Checking remote server setup has ended at ".date("Y-m-d H:i:s").".<br>";
  }

  function canRunServer($localServerType) {
    $errorNumber = 151;
    $remoteServer = "?";

    if (!empty($localServerType)) {
      $errorNumber = 152;
      $remoteServer = $_SERVER["SERVER_SOFTWARE"];
      $remoteServerName = explode("/", $remoteServer)[0]; // Apache || nginx || LiteSpeed
      if ( (strtolower($localServerType) == "apache" && (strtolower($remoteServerName) == "apache" || strtolower($remoteServerName) == "litespeed")) || (strtolower($localServerType) == "nginx" && strtolower($remoteServerName) == "nginx") ) {
        $errorNumber = 0;
      }
    }

    $aReturnValue = array();
    $aReturnValue["result"]=$errorNumber;
    if ($errorNumber != 0) {
      $errorDescriptionLocalized = array();
      $errorDescriptionLocalized["en"] = "The server you are trying to transfer your site to has a different configuration than your local host. Please make sure you are using the same server type (Apache or Nginx). (Error: ".$errorNumber." / Remote Server Name String: ".$remoteServer.")";
      //$errorDescriptionLocalized["de"] = "...";

      $aReturnValue["errorDescription"] = $errorDescriptionLocalized;
    }

    return $aReturnValue;
  }

  function canWriteFiles() {
    $aReturnValue = array();
    $errorNumber = 401;
    $posixUserInfo = "";

    $dir = "../../.";
    clearstatcache(TRUE, $dir);
    if (is_writable($dir)) { $errorNumber = 0; }
    else { if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { $posixUserInfo = " - user: ".posix_getpwuid(posix_getuid())." - euser: ".posix_getpwuid(posix_geteuid())." . "; } }

    $aReturnValue["result"] = $errorNumber;
    if ($errorNumber != 0) {
      $errorDescriptionLocalized = array();
      $errorDescriptionLocalized["en"] = "Your remote server does not allow that user to create files. Make sure your remote path is writable and that user can create files. (Error: ".$errorNumber."".$posixUserInfo.")";
      //$errorDescriptionLocalized["de"] = "...";

      $aReturnValue["errorDescription"] = $errorDescriptionLocalized;
    }

    return $aReturnValue;
  }

  function hasEnoughFreeDiskspaceForDownload($directory) {
    $errorNumber = 201;
    $sizeNeeded = floatval(3*getDirectorySize($directory));
    if (!empty($directory)) {
      $errorNumber = 202;
      $diskFreeSpace = disk_free_space($directory);
      if (!empty($diskFreeSpace)) { $errorNumber = ($diskFreeSpace >= $sizeNeeded) ? 0 : 203; }
    }
    return $errorNumber;
  }

  function getHostTypeAtPath($docRootPath){
    $remoteHostType = 0;//"None";
    if (file_exists($docRootPath."wp-config.php")) { $remoteHostType = 1; } //"Wordpress"
    else if (file_exists($docRootPath."configuration.php")) { $remoteHostType = 2; } //"Joomla"
    else if (file_exists($docRootPath."sites/default/settings.php")) { $remoteHostType = 3; } //"Drupal"
    else if (file_exists($docRootPath."webEdition/we/include/conf/we_conf.inc.php")) { $remoteHostType = 4; } //"Webedition"
    else if (file_exists($docRootPath."typo3conf/LocalConfiguration.php")) { $remoteHostType = 5; } //"Typo3"
    else if (file_exists($docRootPath."application/config/database.php")) { $remoteHostType = 6; } //"Concrete5"
    else if (file_exists($docRootPath."app/config/parameters.yml") && !file_exists($docRootPath."app/config/parameters.php")) { $remoteHostType = 7; } //"ForkCMS"
    else if (file_exists($docRootPath."app/etc/env.php")) { $remoteHostType = 8; } //"Magento"
    else if (file_exists($docRootPath."app/config/parameters.yml") && file_exists($docRootPath."app/config/parameters.php")) { $remoteHostType = 9; } //"Prestashop"
    return $remoteHostType;
  }

  function getDirectorySize($path) {
    $bytestotal = 0;
    $path = realpath($path);
    if($path!==false && $path!='' && file_exists($path)){ foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $object){ $bytestotal += $object->getSize(); } }
    return $bytestotal;
  }

  function canRunSqlFile($db_server, $db_name, $db_username, $db_password) {
    /*
    MySQL error no: https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
    */
    $errorNumber = 301;
    $errorDescription = "Checking database to remote server";
    $currentMampProMysqlVersion = "5.7";
    $mysqliVersion = 1.0;

    if(!empty($db_server) && !empty($db_name) && !empty($db_username) && !empty($db_password)) {
        $errorNumber = 302;
        if (function_exists('mysqli_connect')) {
            $errorNumber = 0;
            $mysqli = new mysqli($db_server, $db_username, $db_password);
            if (mysqli_connect_error()) {
                $mysqliErrNo = mysqli_connect_errno();
                $errorDescription = $mysqli->connect_error;
                if ($mysqliErrNo == 2005) { $errorNumber = 310; } // Unknown db_server
                else if ($mysqliErrNo == 2008) { $errorNumber = 309; } // MySQL Client ran out of memory
                else if ($mysqliErrNo == 2009) { $errorNumber = 308; } // Wrong host info
                else if ($mysqliErrNo == 2003) { $errorNumber = 307; } // Wrong username or password
                else if ($mysqliErrNo == 1044) { $errorNumber = 306; } // Access denied for that database
                else if ($mysqliErrNo == 1045) { $errorNumber = 305; } // Access denied for that username and password
                else if ($mysqliErrNo == 1049) { $errorNumber = 304; } // Unknown database
                else { $errorNumber = 303; } // could not connect with provided information
            }

            if ($errorNumber == 0) { // check connect to database
                $db_selected = mysqli_select_db($mysqli, $db_name); // connection ok -> check database
                if (!$db_selected) { // we couldn't select -> we try to create
                    $db_name = $mysqli->real_escape_string($db_name);
                    $sql = 'CREATE DATABASE '.$db_name; //$sql="CREATE DATABASE '.$db_name.'";
                    if (!mysqli_query($mysqli, $sql)) {
                        $mysqliErrNo = mysqli_errno($mysqli);
                        $errorDescription = $mysqli->error;
                        if ($mysqliErrNo == 1064) { $errorNumber = 312; } // there is a good chance that it's a shared server and that user does not have the root access to create database from php script (the user has given the right informaton but is a shared server so they dont have the root access of the server to create a database)
                        else { $errorNumber = 311; }
                    }
                }
            }

            if ($errorNumber == 0) { // we did connect to the database, now we can check the version
              $infoMysqliVersion = $mysqli->server_info;
              $longMysqliVersion = explode(".", explode("-", $infoMysqliVersion)[0]);
              $mysqliVersion = $longMysqliVersion[0].".".$longMysqliVersion[1];
              if (empty($mysqliVersion)) { $mysqliVersion = 1.0; }
              if (version_compare($currentMampProMysqlVersion, $mysqliVersion, '!=')) { $errorNumber = 313; }
            }

            if ($mysqli) $mysqli->close();
        }
    }

    $aReturnValue = array();
    $aReturnValue["result"] = $errorNumber;
    $aReturnValue["remoteMySQLVersion"] = $mysqliVersion;

    if ($errorNumber != 0) {
        $enLocalErrorDescription = "There was an error while trying to connect to your remote MySQL server database. Make sure the user credentials are correct and that the MySQLi Extension is installed on your remote server. (Error: ".$errorNumber." - ".$errorDescription.")";
        if ($errorNumber == 313) {
              $enLocalErrorDescription = "Your remote MySQL server is different than your local MySQL server (MySQL 5.7). Different database versions could cause data loss while importing/exporting your database.";
        }

        $errorDescriptionLocalized = array();
        $errorDescriptionLocalized["en"] = $enLocalErrorDescription;
        //$errorDescriptionLocalized["de"] = "...";

        $aReturnValue["errorDescription"] = $errorDescriptionLocalized;
    }

    return $aReturnValue;
}

function runCurl($liveUrlPhpString) {
  if(!function_exists('curl_init')) return 'cURL is not available!';
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $liveUrlPhpString); 
  curl_setopt($curl, CURLOPT_FAILONERROR, true);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('phpversion' => phpversion())));
  $output = curl_exec($curl);
  return ($output === FALSE) ? 'An error has occurred while executing cURL: '.curl_error($curl).PHP_EOL : $output;
  }
?>

After you have created your script, type the following https://MyLiveSite/.test/scripts/check.php into your browser.

If the minimum requirements are not met, please contact your host provider to find out how you can change them.

Successful Response

A successful response would be similar to the following … .

Checking remote server setup has started... 

Can run server: Yes 

Can write files: Yes 

Has enough disk space: Yes 

Remote host type: 1 

Remote document root size: 2040708454 

Remote PHP version: 7.2.15 

Remote MySQL version: 5.7; Result: 0 

Checking remote server setup has ended at 2019-03-19 16:07:36.