Author Topic: Running PHP cron under user fail  (Read 1005 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Running PHP cron under user fail
« on: February 08, 2024, 02:25:06 AM »
I tried to run php cron job with the following command:
Code: [Select]
/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:
Code: [Select]
/opt/alt/php82/usr/php
also give error.

If I run the cron as root:
Code: [Select]
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.
« Last Edit: February 08, 2024, 02:30:11 AM by hanliong »
we are web developer in Indonesia with address: Tatamedia Solusindo | web hosting with mutiple choices | discounted software store

Online
*****
Re: Running PHP cron under user fail
« Reply #1 on: February 08, 2024, 02:37:51 AM »
Are you calling this from r00t's crontab / system crontab and want to run as a normal user?
Code: [Select]
sudo -u $USER /opt/alt/php82/usr/php /home/$USER/src/file.phpOtherwise, put the php command in the user's crontab.

Offline
*
Re: Running PHP cron under user fail
« Reply #2 on: February 08, 2024, 02:43:30 AM »
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