Issue
I'm just trying to create a file to be run from a cron job but however I'm getting the below error log.
PHP Warning: require(../app/src/app.class.php): failed to open stream: No such file or directory in /var/www/mosto.in/manual/gateway.php on line 4
PHP Fatal error: require(): Failed opening required '../app/src/app.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/mydomain.in/manual/gateway.php on line 4
My gateway.php file
set_time_limit(0);
require('../app/src/app.class.php');
I'm confused if I'm running the same file on my ssh server using the below path the file not generating any errors & working very fine.
*cd /var/www/mosto.in/manual/
*php gateway.php
Crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /usr/bin/php /var/www/mosto.in/manual/gateway.php > /var/log/gateway.log 2>&1
Please help me.
Thanks in advance.
Solution
Your problem is most likely that the working directory for the cron daemon is not the same as when you execute it manually. See if this works:
* * * * * cd /var/www/mosto.in/manual/ && /usr/bin/php gateway.php > /var/log/gateway.log 2>&1
If it does, I'd consider moving the cd
and php
call into a script file and calling that from your crontab instead - but that might just be me :p
Answered By - fredrik Answer Checked By - Mary Flores (WPSolving Volunteer)