Question

I am attempting to run a php script via cron and I'm hitting a brick wall.

When I run the php script via the command line as root, everything works correctly. When I run the php script via the command line as the user, everything works correctly.

The error that I am getting is: PHP Fatal error: Call to undefined function imagecreatefromstring()

To test I created a php file that has...

    <?php
    var_dump(gd_info());
    ?>

When that file is executed via cron it again says that I have a fatal error. "Call to undefined function gd_info()"

So at this point, I've narrowed it down to GD not loading in the cron environment, but at this point, I don't know what to do to fix the issue.

Was it helpful?

Solution

My guess is you have multiple copies of PHP. You and root use one built with GD, cron uses another due to PATH environment variable inconsistencies.

As a working user (you or root), run

which php

That will give you a full path like /usr/bin/php. Use that path in your cron entry, eg

0 0 * * * /usr/bin/php /path/to/your/script.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top