Running PHP cron under user fail

Started by hanliong, February 08, 2024, 02:25:06 AM

Previous topic - Next topic

hanliong

I tried to run php cron job with the following command:
/usr/local/bin/php /home/xxxxxx/src/file.php

But it returned with error:

-bash: /usr/local/bin/php: Operation not permitted

Trying to run with specified PHP version like:
/opt/alt/php82/usr/php

also give error.

If I run the cron as root:
sudo /usr/local/bin/php /home/xxxxxx/src/file.php

It works perfectly.

So, how can a user run PHP cron in CWP? and How to run PHP cron with specified PHP version if we have multiple PHP version installed?

Thanks.
we are web developer in Indonesia with address: Tatamedia Solusindo | web hosting with mutiple choices | discounted software store

overseer

Are you calling this from r00t's crontab / system crontab and want to run as a normal user?
sudo -u $USER /opt/alt/php82/usr/php /home/$USER/src/file.php
Otherwise, put the php command in the user's crontab.

hanliong

The cronjob is under cwp's user. But the process has never run. No emails come to the inbox as it should be.
So, I tried to login to SSH as root and run that cronjob, and it gave the error permission denied.
If I run it with sudo, it works, and the email goes to the inbox.

That is why I want to know, is PHP cron job just allowed to run under root and not user?

Thanks.
we are web developer in Indonesia with address: Tatamedia Solusindo | web hosting with mutiple choices | discounted software store