We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
[RESOLVED] Vesta - CentOS 7.5 - PHP script is not working in CRON Job Topic is solved
[RESOLVED] Vesta - CentOS 7.5 - PHP script is not working in CRON Job
Hello,
I am new to Vesta CP. Recently I installed CentOS on UpCloud and installed Vesta CP. I have only one user "admin" and one domain name added. I have set a CRON to run a simple test PHP which writes date and time stamp to a file. The script is located under "domain.com/test/crontest.php".
My CRON command is:
The CRON is set to run this script every 5 min. Here is the PHP code of this script:
Neither the script is working nor any Log is written to /var/log/crontest.log file.
Can someone please guide me with the proper command to run this CRON job? Is this something to do with script execution user rights? How can I fix this issue?
Waiting for your valuable reply...
Cheers,
\r
I am new to Vesta CP. Recently I installed CentOS on UpCloud and installed Vesta CP. I have only one user "admin" and one domain name added. I have set a CRON to run a simple test PHP which writes date and time stamp to a file. The script is located under "domain.com/test/crontest.php".
My CRON command is:
Code: Select all
/usr/bin/php /home/admin/web/DOMAIN.COM/test/crontest.php >> /var/log/crontest.log
Code: Select all
#!/usr/bin/php -q
<?php
$logfile = "cronlog.txt";
$datestamp = date("d F Y, H:i:s") . "\n";
file_put_contents($logfile, $datestamp, FILE_APPEND | LOCK_EX);
?>
Can someone please guide me with the proper command to run this CRON job? Is this something to do with script execution user rights? How can I fix this issue?
Waiting for your valuable reply...
Cheers,
\r
Last edited by ruturaaj on Fri Jan 18, 2019 4:21 pm, edited 1 time in total.
Re: Vesta - CentOS 7.5 - PHP script is not working in CRON Job
Ok, the problem is resolved now. I had to make following changes to solve this issue; sharing it here as this may help someone.
Changes in CRON Command
I made some changes in the command; the revised command looks like this:
File Permissions
I checked the CHMOD for the crontest.php and changed it to 755.
User Permissions
I tried the CRON command from SHELL and found some permissions related issues. I added "admin" to "wheel" on my CentOS 7.5 installation and executed CRON command, it worked well this time. Not sure if this was necessary, but I found it on some other forum and so implemented it. Certainly, script started to work after that. Tomorrow, I'm going to try removing "admin" from "wheel" using "gpasswd -d admin wheel" command; let's see if the CRON still continues to work good.
So far so good; the script is running good. Now I'm going to add the actual business logic to this PHP script (some database stuff).
Changes in CRON Command
I made some changes in the command; the revised command looks like this:
Code: Select all
cd /home/admin/web/DOMAIN.COM/public_html/test/; /usr/bin/php -f crontest.php
I checked the CHMOD for the crontest.php and changed it to 755.
User Permissions
I tried the CRON command from SHELL and found some permissions related issues. I added "admin" to "wheel" on my CentOS 7.5 installation and executed CRON command, it worked well this time. Not sure if this was necessary, but I found it on some other forum and so implemented it. Certainly, script started to work after that. Tomorrow, I'm going to try removing "admin" from "wheel" using "gpasswd -d admin wheel" command; let's see if the CRON still continues to work good.
So far so good; the script is running good. Now I'm going to add the actual business logic to this PHP script (some database stuff).
Last edited by ruturaaj on Thu Jan 24, 2019 11:10 am, edited 2 times in total.
-
- Support team
- Posts: 1111
- Joined: Tue Jul 30, 2013 10:18 pm
- Contact:
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: [RESOLVED] Vesta - CentOS 7.5 - PHP script is not working in CRON Job
PHP best practice use http://php.net/manual/en/function.chdir.php for CLI scripts.
Code: Select all
chdir ( __DIR__ );