Its possible to install ghostscript or imagick on the premium hosting?

Website URL

(miabe.page.gd/publier.php)

Error Message

(Fatal error: Uncaught Error: Call to undefined function exec() in /home/vol19_1/infinityfree.com/if0_41101602/htdocs/includes/storage.php:25 Stack trace: #0 /home/vol19_1/infinityfree.com/if0_41101602/htdocs/includes/storage.php(66): resolveGhostscriptBinary() #1 /home/vol19_1/infinityfree.com/if0_41101602/htdocs/publier.php(89): generateCoverWithGhostscript(‘/home/vol19_1/i…’, ‘/home/vol19_1/i…’, 200, 280, 300, 100) #2 {main} thrown in /home/vol19_1/infinityfree.com/if0_41101602/htdocs/includes/storage.php on line 25)

Other Information

(other information and details relevant to your question)

Your issue is not about Ghostscript or Imagick extension, free hosting have these as well.

The issue is that your script tried to use exec() which is not available on free hosting. Premium hosting do allow such function.

8 Likes

Thanks for the info. Does this mean I can’t manipulate PDFs with this offer? Or are there other alternatives?

No, you cannot use Ghostscript / ImageMagick on free hosting.

The real problem is that exec() is disabled on free hosting for security reasons.

Even if Ghostscript/Imagick are installed, your script still won’t work — because it relies on exec(), which is blocked.

So:

  • If you want to keep using your current script → you need premium hosting (they allow exec()).

  • If you must stay on free hosting → you have to rewrite your code using pure‑PHP PDF libraries like TCPDF, FPDI, or FPDF (no exec() required).

If you want to handle PDFs on a free host, here are two possible solutions

Solution 1: Basic PDF Generation (FPDF, Simplest)

FPDF is a lightweight pure-PHP library with no dependencies. Simply download the source code, upload it to your website directory, and you can use it to generate simple PDFs (text, images).

Steps:

  1. Download the FPDF source code: https://www.fpdf.org/en/download.php (select the latest version, unzip it, and upload to your website directory, e.g., /includes/fpdf/);

  2. Create a PHP file for PDF processing (e.g., create_pdf.php):

<?php
// Include the FPDF library (adjust the path based on where you uploaded it)
require_once(__DIR__ . '/includes/fpdf/fpdf.php');

// Initialize the PDF object
$pdf = new FPDF();
$pdf->AddPage(); // Add a page

// Set font (English is supported by default; additional config is needed for Chinese)
$pdf->SetFont('Arial', 'B', 16);

// Write content (parameters: width, height, text, border, line break position, alignment)
$pdf->Cell(0, 10, 'PDF generated on free hosting', 0, 1, 'C');
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(0, 10, 'No exec() or Ghostscript required', 0, 1, 'C');

// Save the PDF to the server (F = save to file, I = download in browser)
// Note: Use absolute path for free hosting, e.g., your path is /home/vol19_1/infinityfree.com/if0_41101602/htdocs/
$savePath = '/home/vol19_1/infinityfree.com/if0_41101602/htdocs/generated.pdf';
$pdf->Output($savePath, 'F');

// Verify if generation was successful
if (file_exists($savePath)) {
    echo "PDF generated successfully! Path: {$savePath}";
} else {
    echo "PDF generation failed. Please check path permissions.";
}
?>

Solution 2: Advanced PDF Processing (TCPDF, Supports Chinese/Cover/Editing)

If you need more complex operations (e.g., generating PDF covers, handling Chinese, merging PDFs), TCPDF is recommended — it’s also compatible with free hosting:

Steps:

  1. Download the TCPDF source code: https://github.com/tecnickcom/TCPDF (unzip it and upload to /includes/tcpdf/);

  2. Example: Generate a PDF with an image cover (adapted to your generateCoverWithGhostscript requirement):

<?php
// Include the TCPDF library
require_once(__DIR__ . '/includes/tcpdf/tcpdf.php');

// Create a PDF instance (set page orientation, unit, format)
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);

// Set basic PDF information
$pdf->SetCreator('Your Website');
$pdf->SetTitle('PDF Cover Example');
?>

Summary

  1. Solution 1 (FPDF) is ideal for simple English PDF generation on free hosting, with zero external dependencies and easy deployment.
  2. Solution 2 (TCPDF) supports advanced features like cover images and multi-language (including Chinese) for more complex PDF needs, still fully compatible with free hosting restrictions.
  3. Both solutions avoid using exec() (blocked on free hosting) and replace Ghostscript/Imagick with pure-PHP logic.
1 Like

Thank you very much, I was using Ghostscript to automatically generate the covers of PDFs downloaded on my app , I retrieve the first page of the PDF downloaded by the user and convert it into an image for the cover

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.