Score:0

HTTP ERROR 500 when running to linux server?

sc flag

I have this PHP code for importing excel to mysql using PhpSpreadsheet in xampp. This code is OK when running in windows environment but if I hosted it to a Linux Server(Ubuntu 22.04) using XAMPP Linux got an error "HTTP ERROR 500". I've installed all packages and extension needed for PhpSpreadsheet based here on phpspreadsheet.readthedocs.io documentation. If this error is for the server side what should I do? Please help

These are my codes for my import file

composer.json

{
"name": "mark/import1",
"autoload": {
    "psr-4": {
        "Mark\\Import1\\": "src/"
    }
},
"authors": [
    {
        "name": "mark"
    }
],

 "require": {
    "phpoffice/phpspreadsheet": "^1.28"
},
"config": {
    "platform": {
        "php": "8.1"
    }
}
}

import code

<?php
 $con = mysqli_connect('localhost','root','','db_import');

 require 'vendor/autoload.php';

 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

  if(isset($_POST['save_excel_data']))
  {
   $fileName = $_FILES['import_file']['name'];
   $file_ext = pathinfo($fileName, PATHINFO_EXTENSION);

   $allowed_ext = ['xls','csv','xlsx'];

  if(in_array($file_ext, $allowed_ext))
  {
    $inputFileNamePath = $_FILES['import_file']['tmp_name'];
    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileNamePath);
    $data = $spreadsheet->getActiveSheet()->toArray();

foreach($data as $row)
{
            $fullname = $row['0'];
            $email = $row['1'];
            $phone = $row['2'];
            $course = $row['3'];
    
    $studentQuery = "INSERT INTO students (fullname,email,phone,course) 
                            VALUES('$fullname','$email','$phone','$course')";
            $result = mysqli_query($con, $studentQuery);
            $msg = true;    
}
 }
 }
David avatar
cn flag
Look at the slashes in your code. This is for a Windows system. For a Linux system they go the other way. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileNamePath
moski avatar
sc flag
@David hi sir. I've already did that but still problem exist and also run this in a ubuntu desktop22.04 but no luck
David avatar
cn flag
You have changed ALL the wrong slashes everywhere?
moski avatar
sc flag
@David yes sir by changing to forward slash /
moski avatar
sc flag
@Jos I dont see any apache2 from /var/log
moski avatar
sc flag
@Jos the apche2 was included in XAMPP but i didnt see any error.log /opt/lampp/apache2 (scripts,htdocs and conf)
uz flag
Jos
I understand the log file is located elsewhere in an XAMPP installation. Please find it and look up the actual PHP error that caused the 500 error message. I will remove my previous comments.
moski avatar
sc flag
@jos sorry but i dont see any error logs :(
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.