0

I have a problem moving my script from one server to one other.

The PHP script read a PDF file and create an image for each page of the pdf. This script currently works in an environment that has these characteristics

  • PHP version: 7.4.8
  • Imagick version: 3.4.4

Now I have moved the script to an environment that has these characteristics:

  • PHP version: 7.4.28
  • Imagick version: 3.7.0

The code is:

$img = new Imagick($percorsoBaseDir); //LINE OF THE ERROR
$img->setResolution(600, 600);
$num_pages = $img->getNumberImages();
$img->setImageCompressionQuality(100);
$images = NULL;
for ($i; $i < $num_pages; $i++)
{
   ..... [My script] ....
}

And the error is:

AH01071: Got error 'PHP message: PHP Fatal error: Uncaught ImagickException: Failed to read the file in /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php:222\nStack trace:\n#0 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php(222): Imagick->readImage()\n#1 /var/www/vhosts/mysite.com/httpdocs/wp-includes/shortcodes.php(356): step_2_function()\n#2 [internal function]: do_shortcode_tag()\n#3 /var/www/vhosts/mysite.com/httpdocs/wp-includes/shortcodes.php(228): preg_replace_callback()\n#4 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/helpers/helpers.php(247): do_shortcode()\n#5 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/templates/shortcodes/vc_column_text.php(31): wpb_js_remove_wpautop()\n#6 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/classes/shortcodes/core/class-wpbakeryshortcode.php(451): require('/var/www/...', 

I also tried throwing:

getcwd() //to verify that the file exists

and:

is_readable ($ pathBaseDir) //to verify that the file exist and is readable
is_writable ($ pathBaseDir) //to verify that the file exist and is writable

and they both return TRUE.

I also checked that the file loaded correctly in the file system and that I could open it from the browser.

I can't understand what can be the error, has something similar happened to you? How could I solve?

Thank you!

  • I feel like there is more to that error `Failed to read the file in /var/www/vhosts/.....` Like it may end saying that it's a permission issue or something else? Is there anything in your php error logs that may shine more light on that truncated error? – JNevill Apr 06 '22 at 14:17
  • @JNevill I edit my question adding the full error message. – Sebastiano S. Apr 06 '22 at 14:39
  • Does this file exist: `/var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php`? – JNevill Apr 06 '22 at 14:41
  • @JNevill the "Step_2.php" file exist. I have check also the absolute path. – Sebastiano S. Apr 06 '22 at 15:01

1 Answers1

0

I find the problem: I have installed the Ghost Script in my server with this command:

apt-get install ghostscript 

And now it works!