Custom cron job not working

Hi.

I’ve created a user (user1), under this user I’ve added a website with cron.php file in the root folder. The problem is that when i run the cron.php file using command line (/usr/bin/curl https://domain.com/cron.php), everything works as expected. But when i add the same command as a cron job through Hestia interface, it doesn’t work.

Please provide more information…

It might be a permission issue

Thanks for your reply, eris!

The path to cron.php is: /home/user1/web/domain.com/public_html/cron.php. All folders inside ‘public_html’ folder are set to 755, all files to 644.

domain.com’ folder is set to 551, ‘public_html’ to 751 (by default). I’ve also executed the ‘sudo chown -R user1:user1 /home/user1/web’ command. And tried setting permission for the cron.php file to 755.

I’ve logged in as ‘user1’ in Hestia Panel and added a cron job - /usr/bin/curl ht*ps://domain.com/cron.php - at specific time. There is some php code inside cron.php, which changes some information on my website.

When i run the ‘/usr/bin/curl https://domain.com/cron.php’ command through command line via SSH as root user, everything works fine. When i directly open the htps://domain.com/cron.php in my browser, everything works fine as well. But when i add a cron job (/usr/bin/curl htps://domain.com/cron.php) as user1 in Hestia Panel at specific time, the cron script doesn’t work. I receive no errors on my admin email either.

Sorry for the ‘htps’ and * in urls, the validator says i can’t use more than 2 links as a new user.

If you want to run a php script use

/usr/bin/php /home/user1/web/domain.com/public_html/cron.php

I’ve already tried that. The problem with this method is that my cron.php script reads text from a bunch of text files with file_get_contents function and relative paths. When i run the ‘/usr/bin/php /home/user1/web/domain.com/public_html/cron.php’ through command line, it throws the ‘Failed to open stream: No such file or directory’ errors at me.

I believe it’s because of relative paths in my script. I have couple of dozens of websites (and more to come) with the same cron.php file, and it would be tiresome to adjust every cron.php file to have unique absolute paths inside. That’s why i want to run my cron.php with curl.

I don’t understand why the curl method works with command line as root user but not as an added cron job in Hestia Panel.

/usr/bin/curl https://domain.com/cron.php

Should work fine

But it doesn’t. Are there error log files for cron jobs? I couldn’t find any.

No there are no error logs.

If you are using an idn domain name make sure you use the ascii format.

You should also be able to login with ssh as the user and run the command to see if it is working.

Or check the log files for a request…

my.server.ip - - [04/Sep/2022:21:29:02 +0000] "GET /wp-cron.php HTTP/2.0" 200 0 "-" "curl/7.74.0"
my.server.ip - - [04/Sep/2022:21:30:01 +0000] "GET /wp-cron.php HTTP/2.0" 200 0 "-" "curl/7.74.0"

I’m not using an idn domain name.

I’ve logged in as user1 with SSH and run the command. Works perfectly fine. I thought that maybe something was wrong with the server timezone, that it wasn’t aligned with my cron testing dates, but i double checked my server date and timezone with ‘date’ command (while logged in as user1) and it was correct. I don’t get it.

I’m afraid i don’t understand how to use those commands. What is wp-cron.php? I don’t use WordPress. And what are those dates in square brackets ([04/Sep/2022:21:29:02 +0000])?

I think I’ve managed to make it work. I’ve restarted the cron service and it seems that my cron job is working now. It seems that after I gave permission to user1 by the ‘sudo chown -R user1:user1 /home/user1/web’ command, i needed to restart the cron service.

Need more testing.

Edit: Yeah, it’s working. Thanks for your time, eris!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.