1

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.

Scott Hack
  • 33
  • 5

1 Answers1

1

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
Phil
  • 157,677
  • 23
  • 242
  • 245
  • Thank you, that did the trick! Out of curiosity, do you by chance have any idea how I could find out what environment is being used by default for cron? – Scott Hack May 06 '14 at 04:20
  • @ScottHack Run a cron script that dumps the output of `env` and `which php` to a file. – Phil May 06 '14 at 04:22