Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cron commands do not run, getting output /bin/sh: 1: php: not found

I have the following inside my crontab -e

0,30 * * * * cd /usr/local/bin && php /var/www/artisan my_command > /var/www/storage/logs/cron.log 2>&1

But I get the following inside /var/www/storage/logs/cron.log.

/bin/sh: 1: php: not found

I tried running the following for reference:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# which php
/usr/local/bin/php
# whoami
root

I am running cron from inside a docker image (OS: Ubuntu) in a Laravel project.
I tried changing the path in different ways, but it still gave the same error.
There were a lot of similar questions, but I didn’t manage to find my answer…

>Solution :

The current directory isn’t in the PATH (and it shouldn’t be).

Simply skip the useless cd command and run /usr/local/bin/php instead:

0,30 * * * * /usr/local/bin/php /var/www/artisan my_command > /var/www/storage/logs/cron.log 2>&1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading