How can I get crontab to use a different PHP installation location?

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have a MAMP setup which runs PHP 5.3.5 on my Mac OS X 10.5 computer. I am trying to install a crontab that executes a PHP script, which is located on my MAMP server. I can only get the crontab to execute if I use the php installation from /usr/bin/php, which is version 5.2.15. In other words, this is the pre-installed MAC OS X installation of PHP. How can I use my MAMP's version of PHP when executing the crontab? I am not knowledgeable enough with unix to install a new version of PHP at /usr/bin/php, though would this work?

I want crontab to execute my PHP script using MAMP's version of PHP; this is because I know that the script runs successfully, and I get the desired output. However, when I try executing the crontab using the system default PHP installation at /usr/bin/php, I get Fatal PHP errors.

--

In case this might be useful, here is the outcome of /usr/bin/php vs. MAMP's version. The first code example executes my php script successfully:

$  MAMP_PHP_PATH="/applications/mamp/bin/php5.3/bin/php"
$  $MAMP_PHP_PATH -f /path/to/my/script.php

Now, here's what happens when I simply run the following command:

$  # whereis php in this case returns usr/bin/php
$  php -f /path/to/my/script.php

Results in the following error (formatting mine):

Fatal error: require_once(): 
Failed opening required '/path/to/includes/initialize.php' 
(include_path='.:') in /path/to/my/script.php on line 3

Finally, this is what my crontab file looks like (with MAMP's php):

15 * * * * /Applications/MAMP/bin/php5.3/bin/php /path/to/my/script.php

And without MAMP's php:

15 * * * * php /path/to/my/script.php

Thanks

profilepic.png
manpreet 2 years ago

Set the environment variables you need in the crontab. For example:

PATH=/Applications/MAMP/bin/php5.3/bin:/usr/local/bin:/usr/bin:/bin
MAMP_PHP_PATH=/applications/mamp/bin/php5.3/bin/php
15 * * * * php /path/to/my/script.php

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.