Home  >  Q&A  >  body text

phpspreadsheet works on local XAMPP server but not on IIS (Windows Server 2012 R2)

I developed a website using php and mysql where users have to upload excel files. In local server (XAMPP) I downloaded phpspreadsheet and was able to upload excel file to mysql database. But when I am working on the same thing on IIS (Windows server 2012 r2), the excel file cannot be uploaded to mysql and the basic code below is not working on IIS (Windows server 2012 r2) and shows

This page is not working properly. 10.10.10.2 is currently unable to process this request. HTTP error 500

In IIS Windows Server 2012 R2, I am using php 7.4.13. The code below works on XAMPP SERVER but not on IIS (Windows Server 2012 R2)

<?php

require 'vendor/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'This new hello World !');

$writer = new Xlsx($spreadsheet);
$writer->save('ThisMyExcelExample.xlsx');
?>

P粉136356287P粉136356287215 days ago386

reply all(1)I'll reply

  • P粉156415696

    P粉1564156962024-02-22 00:53:03

    On Windows Server, there are more steps involved. Make sure you follow these steps

    • Open the Server Manager application and execute "Add Roles and Function” wizard.
    • On the Server Roles page, select Web Server (IIS) , be sure to enable CGI
    • Install PHP on IIS
    • In the Actions pane you will be able to select Add Module Mapping. Enter the necessary details to tell IIS that *.php files should be run by php-cgi.exe
    • Now, select your server in the Connection pane of IIS Manager and select Default Document. In the subsequent Actions pane, click Add... and add "index.php".
    • Also make sure PHP is configured on IIS

    Please check out the following articleHow to install Windows with IIS It's helpful and will guide you with attached step by step images

    reply
    0
  • Cancelreply