Search code examples
phpapacheubuntuwebserverapache2.4

Apache2 Internal Server Error 500


I have issue with my imagecreatefrompng function, it was working before on shared hosting but when I migrated it to apache2 installed on ubuntu with php5 its not loading with internal server error 500

PHP version 5.5.9 Apache 2.4 Hosted on Ubuntu

<?php
  //Set the Content Type
  header('Content-type: image/jpeg');

  // Create Image From Existing File
  $jpg_image = imagecreatefrompng('icon.png');

  // Allocate A Color For The Text
  $white = imagecolorallocate($jpg_image, 0, 0, 0);

  // Set Path to Font File
  $font_path = 'OpenSans-Bold.ttf';

  // Set Text to Be Printed On Image
  $text = "1";

  // Print Text On Image
  imagettftext($jpg_image, 10, 0, 18, 20, $white, $font_path, $text);
  imagesavealpha($jpg_image, true);
  // Send Image to Browser
  imagepng($jpg_image);

  // Clear Memory
  imagedestroy($jpg_image);
?>

I tried

1- Restarting Web Server Apache2 many times 2- Changing image file to verify if the file is corrupted 3- Installing few components related to images in php5 like php5-imagick or php5-exactimage 4- Setting EnableSendFile to Off in apache2.conf 5- Tried to put code in try catch but didn't able to catch exception

I am unable to resolve this issue? Do I need to install any php component or upgrade anything?

Thanks,

Regards,


Solution

  • I got it, actually I didn't install the GD component for PHP5. To use this library for PNG and JPEG files GD component has to be installed.