Question

So I am plagued with this issue like many others have been but with no solution.

The Issue: commands issued by a cron task do not run and give the message: Laravel requires the Mcrypt PHP extension.

I can run commands through artisan and they work fine. I am using MAMP on OSX 10.8.

I've quadrupal checked my .bash_profile to ensure the correct PATH is set which is: export PATH=/Applications/MAMP/bin/php/php5.4.4/bin:$PATH. Confirmed by which php in terminal. php -v confirms PHP 5.4.4 is being used. php -i confirms mcrypt extension is installed and enabled. Even adding die(phpversion().PHP_EOL); to vendor/laravel/framework/src/Illuminate/Foundation/start.php it's confirmed that it's using the correct version.

So I'm stumped. I don't know why cronjobs aren't recognizing either the correct PHP version or that the mcrypt extension is installed. What can I try?

Was it helpful?

Solution

Don't rely on PATH being set for cronjob through .bash_profile (it's a shell feature and cronjobs are not running through a shell), you should rather use something like

* * * * * /Applications/MAMP/bin/php/php5.4.4/bin/php-something? /path/to/vendor/laravel/framework/src/Illuminate/Foundation/start.php

A test could be something like this:

# /tmp/test.php
<?php file_put_contents('/tmp/a_test', `id`."\n".var_export($_ENV, true)."\n".var_export(extension_loaded('mcrypt'), true));
# in crontab
* * * * * /Applications/MAMP/bin/php/php5.4.4/bin/php-something? /tmp/test.php

Run php /tmp/test.php one time manually to spot the differences between you running the script, and cron; and always try to use absolute paths in crontab (in this case to your php binary).

OTHER TIPS

This is probably a PHP problem, look at the code reponsible for that message:

if ( ! extension_loaded('mcrypt'))
{
    die('Laravel requires the Mcrypt PHP extension.'.PHP_EOL);

    exit(1);
}

Test your php on the command line running:

php -r 'echo PHP_EOL . (extension_loaded("mcrypt") ? "loaded" : "not loaded") . PHP_EOL . PHP_EOL;'

MCrypt is installed and available to php? Test it running:

php -i | grep  mcrypt

It must show you at least:

mcrypt support => enabled
mcrypt_filter support => enabled

EDIT:

Another possibility is cron running a different php (php, php-cli, php-cgi) and when you explicitly selected the right one it worked. Take a look at all your php.ini files to see if mcrypt is enabled in all of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top