nitrammit
nitrammit

Reputation: 143

Install PHP MCrypt for CLI

Setting up a CRON job for a Laravel 4 application and I've ran into a roadblock. The CRON is working, but it's returning a "Laravel requires the Mcrypt PHP extension" error to the CRON log file I have set up.

Here is my CRON job which executes an Artisan command every minute:

* * * * * /usr/bin/php /Users/Tim/Dropbox/orbis/artisan orbis:clear-players > /Users/Tim/cron.log

This command runs if I cd into the Laravel project folder (/Users/Tim/Dropbox/orbis), but the MCrypt isn't being detected for the CRON.

I read that sometimes the CLI uses a different php.ini file and that MCrypt may not be enabled for the CLI specifically. How can I get MCrypt installed for the CLI as well?

Not sure how relevant this is, but I've added the following to my .bash_profile:

export PATH=/Applications/MAMP/bin/php/php5.4.4/bin:$PATH

Does that mean the CLI should be using the same PHP configuration file etc as MAMP?

Sorry if this is a stupid question, but my knowledge is limited for this.

Thanks!

Upvotes: 2

Views: 1183

Answers (1)

Giacomo1968
Giacomo1968

Reputation: 26056

Your cron indicates the PHP path you are using is the OS X install of PHP in /usr/bin/php:

* * * * * /usr/bin/php /Users/Tim/Dropbox/orbis/artisan orbis:clear-players > /Users/Tim/cron.log

But your export path shows the MAMP PHP install path which implies /Applications/MAMP/bin/php/php5.4.4/bin/php:

export PATH=/Applications/MAMP/bin/php/php5.4.4/bin:$PATH

So pretty sure that is not relevant… But maybe it can help you all things considered… Read on to understand.

Basically mcrypt is not a part of the OS X install of PHP. There are guides & discussions on how to handle here and here. In general, the base OS X install of PHP is never up to par. It’s for part of that reason tools like MAMP exist. You can basically go nuts compiling it from source on your OS X install. Which can work, but yeah. MAMP.

But that said, if you have MAMP installed, you could modify your cron to use the MAMP install of PHP which should have mcrypt installed. Check the phpinfo() in MAMP from the browser & do a search for mcrypt to confirm.

If so, just change your cron to use MAMP’s PHP instead like so:

* * * * * /Applications/MAMP/bin/php/php5.4.4/bin/php /Users/Tim/Dropbox/orbis/artisan orbis:clear-players > /Users/Tim/cron.log

And it should work.

Upvotes: 1

Related Questions