Search code examples
phplinuxapachemime-typescaptcha

Can't render dynamically created image in PHP (Apache2)


I'm trying to render captcha Image on a page as follows:

<img src="part/captcha_image.php?rand=<?php echo rand(); ?>" id='captchaimg' alt="captcha image">

Image is returned in captcha_image.php with:

header('Content-Type: image/jpeg'); // defining the image type to be shown in browser widow
imagejpeg($image); //showing the image

And on windows machine on xampp it's showing without any problems but on linux with manual apache2 installation image doesn't renders and in browser's developer's tools i see following errors:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) (Shown on chrome and firefox)

http://localhost/app/part/captcha_image.php?rand=1653484771 Failed to load resource: net::ERR_CACHE_MISS (only shown on chrome)

What am I missing?


Solution

  • As @Cheery suggested in comments I was missing gd module which is responsible for creation and manipulation of image files . Command sudo apt-get install php5-gd && sudo service apache2 restart fixed my problem.