php - Apache2 内部服务器错误 500

标签 php apache ubuntu webserver apache2.4

我的 imagecreatefrompng 函数有问题,它之前在共享主机上工作但是当我将它迁移到安装在 ubuntu 上的 apache2 和 php5 时它没有加载内部服务器错误 500

PHP 版本 5.5.9 Apache 2.4 托管在 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);
?>

我试过了

1- 多次重启 Web 服务器 Apache2 2- 更改图像文件以验证文件是否已损坏 3- 在 php5 中安装一些与图像相关的组件,如 php5-imagick 或 php5-exactimage 4- 在 apache2.conf 中将 EnableSendFile 设置为 Off 5- 尝试将代码放入 try catch 但未能捕获异常

我无法解决这个问题?我需要安装任何 php 组件或升级任何东西吗?

谢谢,

问候,

最佳答案

我明白了,其实我并没有安装PHP5的GD组件。要将此库用于 PNG 和 JPEG 文件,必须安装 GD 组件。

关于php - Apache2 内部服务器错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37055716/

相关文章:

php - 如何发送 UTF-8 电子邮件?

apache - .htaccess 和 seo 友好的 url

apache - Ubuntu 16.04 无法启用 .htaccess

git - 为什么我经常需要在 SSH 中输入密码

php - 具有相同名称的 WSDL 函数。如何选择一个?

php - 使用preg_replace函数不会插入mysql

php - Htaccess 使用 FastCGI 重写

mysql - MariaDB 拒绝远程连接

javascript - 如何使用ajax从一个php页面获取数据并使用ajax将其传递到另一个php页面

Apache 将时间戳记录到 Date typescript