Xampp not executing some php scripts on linux

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Xampp not executing some php scripts on linux

Postby dennismaina » 22. December 2020 09:22

Hello,
I'm currently using Xampp version 7.45 on my kali Linux machine GNOME version 3.36.4.
Previously I was developing my project on a windows machine running the same version of Xampp(7.4.5) then I decided to switch to Linux. Suddenly some of my PHP scripts especially those related to inserting data into the database are not executing. FOR example, I have this user registration page, but after registering no record is inserted into the database and the same functionality is doing just fine when I switch back to windows. Is this a bug or are there some additional configurations needed?
dennismaina
 
Posts: 5
Joined: 22. December 2020 09:13
XAMPP version: 7.4.5
Operating System: Kali GNU/Linux Rolling

Re: Xampp not executing some php scripts on linux

Postby Altrea » 22. December 2020 10:54

Hi,

How could we know without knowing your script?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Xampp not executing some php scripts on linux

Postby dennismaina » 23. December 2020 06:59

I'm using a class where I've coded all my functions and here is the function saving the user records.
Code: Select all
     public function save($username,$column, $value){
      $query = $this->db->prepare('SELECT * FROM ' . $this->table . ' WHERE username = :val1');
      $query->bindParam('val1', $username);
      $result =$query->execute();
     
      if ($result AND $row = $query->fetch()){
         $this->id = $row['id'];
          $query2 = $this->db->prepare('UPDATE ' . $this->table . " SET `$column` = :val1 WHERE `id` = :val2");
          $query2->bindParam('val1', $value);
          $query2->bindParam('val2', $this->id);
          $result2 = $query2->execute();
          return $result2;
       }
       else{
          $query2 = $this->db->prepare('INSERT INTO ' . $this->table . " (`username`, `$column`) VALUES (:val1, :val2)");
          $query2->bindParam('val1', $username);
          $query2->bindParam('val2', $value);
          $result2 = $query2->execute();
          return $result2;
       }
       return $result;
    }


Basically, the code first checks if a user record with the same username exists and then updates it, if it doesn't exist then it is created.
The part making me think that it's something to do with Xampp is that the same code is executing on windows Xampp.
dennismaina
 
Posts: 5
Joined: 22. December 2020 09:13
XAMPP version: 7.4.5
Operating System: Kali GNU/Linux Rolling

Re: Xampp not executing some php scripts on linux

Postby Altrea » 23. December 2020 07:06

I don't see any error handling!?
MariaDB can be very informativ if something doesn't went well, but only if you use them.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Xampp not executing some php scripts on linux

Postby dennismaina » 23. December 2020 07:12

I'm doing general error handling on the whole site since I'm using an MVC so all errors are captured by the same script. I have a class for dealing with that here is the snippet.

Code: Select all
class Errs {

  public function generalErr($error) {
    Errs::log($error, FILE_ERR_LOG_FILE);
  }

  public function mailErr($error) {
    Errs::log($error, FILE_ERR_LOG_FILE);
  }

  public function fatalErr($error) {
    Errs::log($error, FILE_FATAL_ERR_LOG_FILE);
  }

  public function log($error, $file) {
    if (is_dir(ERR_HANDLER_PATH . ERR_HANDLER_LOG_FOLDER)) {
      write(ERR_HANDLER_PATH . ERR_HANDLER_LOG_FOLDER . '/' . Errs::raStr() . $file, trim($error) . linending() . '***** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - *****' . linending());
    }
  }

  public function raStr() {
    return (ERR_APPEND_RAND_STRING ? substr(md5(uniqid(rand(),1)), 3, 30) . '-' : '');
  }

}

// Initiate the class..
$DDEH = new Errs();

if (ERR_HANDLER_ENABLED) {
  // Switch off display errors..
  @ini_set('display_errors', 0);
  // Set error reporting level..
  error_reporting(E_ALL);
}

function linending() {
  $newline = "\r\n";
  if (isset($_SERVER["HTTP_USER_AGENT"]) && strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), 'win')) {
    $newline = "\r\n";
  } else if (isset($_SERVER["HTTP_USER_AGENT"]) && strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), 'mac')) {
    $newline = "\r";
  } else {
    $newline = "\n";
  }
  return (defined('PHP_EOL') ? PHP_EOL : $newline);
}

function sysFatalErr() {
  global $DDEH;
  $error = error_get_last();
  if (isset($error['type'])) {
    if ((defined('E_ERROR') && $error['type'] == E_ERROR) || $error['type'] == 4) {
      $string = '[Error Code: ' . $error['type'] . '] ' . $error['message'] . linending();
      $string .= '[Date/Time: ' . date('j F Y @ H:iA') . ']' . linending();
      $string .= '[Fatal error on line ' . $error['line'] . ' in file ' . $error['file'] . ']';
      if (ERR_HANDLER_DISPLAY) {
        echo '<div style="background:#ff9999"><p style="padding:10px;color:#fff">A fatal error has occurred. For more details please view "' . ERR_HANDLER_LOG_FOLDER . '/' . FILE_FATAL_ERR_LOG_FILE . '".</div>';
      }
      $DDEH->fatalErr($string);
    }
  }
}

function sysErrorhandler($errno, $errstr, $errfile, $errline) {
  global $DDEH;
  if (!(error_reporting() & $errno)) {
    return;
  }
  if (!method_exists($DDEH,'generalErr') || !method_exists($DDEH,'fatalErr')) {
    return;
  }
  switch ($errno) {
    case E_USER_ERROR:
      $string = '[Error Code: ' . $errno . '] ' . $errstr . linending();
      $string .= '[Date/Time: ' . date('j F Y @ H:iA') . ']' . linending();
      $string .= '[Error on line ' . $errline . ' in file ' . $errfile . ']';
      if (ERR_HANDLER_DISPLAY) {
        echo '<div style="background:#ff9999"><p style="padding:10px;color:#fff">A fatal error has occurred. For more details please view "' . ERR_HANDLER_LOG_FOLDER . '/' . FILE_FATAL_ERR_LOG_FILE . '".</div>';
      }
      $DDEH->fatalErr($string);
      exit;
      break;

    case E_USER_WARNING:
      $string = '[Error Code: ' . $errno . '] ' . $errstr;
      $string .= '[Date/Time: ' . date('j F Y @ H:iA') . ']' . linending();
      $string .= '[Error on line ' . $errline . ' in file ' . $errfile . ']';
      if (ERR_HANDLER_DISPLAY) {
        echo '<div style="background:#ff9999"><p style="padding:10px;color:#fff">An error has occurred. For more details please view "' . ERR_HANDLER_LOG_FOLDER . '/' . FILE_ERR_LOG_FILE . '".</div>';
      }
      $DDEH->generalErr($string);
      break;

    case E_USER_NOTICE:
      $string = '[Error Code: ' . $errno . '] ' . $errstr . linending();
      $string .= '[Date/Time: ' . date('j F Y @ H:iA') . ']' . linending();
      $string .= '[Error on line ' . $errline . ' in file ' . $errfile . ']';
      if (ERR_HANDLER_DISPLAY) {
        echo '<div style="background:#ff9999"><p style="padding:10px;color:#fff">An error has occurred. For more details please view "' . ERR_HANDLER_LOG_FOLDER . '/' . FILE_ERR_LOG_FILE . '".</div>';
      }
      $DDEH->generalErr($string);
      break;

    default:
      $string = '[Error Code: ' . $errno . '] ' . $errstr . linending();
      $string .= '[Date/Time: ' . date('j F Y @ H:iA') . ']' . linending();
      $string .= '[Error on line ' . $errline . ' in file ' . $errfile . ']';
      if (ERR_HANDLER_DISPLAY) {
        echo '<div style="background:#ff9999"><p style="padding:10px;color:#fff">An error has occurred. For more details please view "' . ERR_HANDLER_LOG_FOLDER . '/' . FILE_ERR_LOG_FILE . '".</div>';
      }
      $DDEH->generalErr($string);
      break;
  }
  return true;
}
function write($file, $data) {
  file_put_contents($file, $data, FILE_APPEND);
}
dennismaina
 
Posts: 5
Joined: 22. December 2020 09:13
XAMPP version: 7.4.5
Operating System: Kali GNU/Linux Rolling

Re: Xampp not executing some php scripts on linux

Postby Altrea » 23. December 2020 07:29

Based on your shown code i cannot see any problem to get this running on linux.
But as already said, MariaDB reports any kind of problems. Either your error handling does not catch all of them, or it has reported a problem you didn't realized yet.
It is not possible for us to debug a whole MVC custom code application, sorry.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Xampp not executing some php scripts on linux

Postby dennismaina » 23. December 2020 08:10

Okay, let me try adding the MariaDB error handling and see if that will help. I'll let you know if anything pops up. Thanks.
dennismaina
 
Posts: 5
Joined: 22. December 2020 09:13
XAMPP version: 7.4.5
Operating System: Kali GNU/Linux Rolling

Re: Xampp not executing some php scripts on linux

Postby dennismaina » 23. December 2020 08:58

Thanks, @Altrea. Through the MariaDB error logging, I was able to fix the issue. So apparently MariaDB does not allow a column in a table to be left without a default value so I had to set every column default value to NULL and now everything I working fine.
The issue is now fixed.
All thanks to the Apache community.
dennismaina
 
Posts: 5
Joined: 22. December 2020 09:13
XAMPP version: 7.4.5
Operating System: Kali GNU/Linux Rolling

Re: Xampp not executing some php scripts on linux

Postby Altrea » 23. December 2020 09:11

You are welcome :)
Happy coding 8)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 22 guests