Ubuntu 15.10 php file cron job - php

So I have a PHP file which I periodically run through cronjob on Ubuntu 12.04 by:
sudo crontab -e
00 00 * * * /usr/bin/php /var/www/file.php (To run at midnight)
It runs successfully.
Then I tried doing the same on Ubuntu 15.10 by:
sudo crontab -e
00,30 * * * * /usr/bin/php /var/www/html/----file.php (To run every half hour)
But this time the file won't run. Even the file permissions have been set to grant the read and execute permissions. Any help on this please?

Related

cron not running on ubuntu 16.04 laravel

I have php 7.2 installed in ubuntu 16.04. (/usr/bin/php7.2 is there not /usr/bin/php)
I have set following commnad to rub cron:
* * * * * /usr/bin/php /var/www/html/artisan schedule:run >> /dev/null
2>&1
or should I write below command
* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1
yestreday, I kill cron process to stop running cron and started again with following command
sudo service cron restart
but somehow, cron is not running automatically.
Any suggestions would be great.

Laravel cronjob schedule command not firing on production

I have 7 different schedule commands on kernel.php and one of those is not firing when running the schedule.
kernel.php
....
$schedule->command('my:command')->hourlyAt(15); // this wont run
...
Running php artisan my:command manually on command line works fine.
Also when running the scheduler on our dev server, all commands works fine. The problem is only on production server.
There are no errors on log files.
Any ideas what might be wrong?
I'm using Laravel 5.6
UPDATED:
The problem was wrong artisan path on laravel forge scheduler
Have you add following cron entry as per your project folder path ?
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
please check with following commands
crontab -l
If not ?
open crontab by
crontab -e
add * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 entry at the end of file
save file and run following commands
sudo service cron restart
again check with crontab -l
this command will return already set cronjob
i hope it helps :)

Setup a cronjob for PHP script in ubuntu & PHP

I want to setup a cronjob for PHP script in ubuntu
I enter this command in terminal
$ crontab -e
Then I choose nano editor which is recommended by ubuntu. Then I enter the blow line into that. Then I press control+C, it asking Y/N for save. I press Y and F2 for close.
* */2 * * * root php /var/www/html/script.php
Other things I've tried:
* */2 * * * /var/www/html/script.php
* */2 * * * root /var/www/html/script.php
After that, I restart cron using the below command.
sudo /etc/init.d/cron restart
Then I check crontab list using crontab -l, it says no cron job set for the root user.
I tried to directly create a crontab.txt file into the cron.hourly / cron.d directory with one of the above line.
I tried numerous forum and all says crontab -e then enter or create crontab file inside cron directory. Nothing is helping me. I am scratching my head.
What is the correct way to create cronjob for php script in ubuntu 16.04 & php version 7.0
Try like this to set crontab using root user,
sudo crontab -e
Do your changes via nano or vim. Finally save and quit
* */2 * * * /var/www/html/script.php
* */2 * * * root /var/www/html/script.php
No need to restart again using this sudo /etc/init.d/cron restart
Try this one (as root user):
1. sudo crontab -e
* */2 * * * php -f /var/www/html/script.php > /dev/null 2>&1
OR
* */2 * * * cd /var/www/html/; php -f script.php > /dev/null 2>&1
for crontabs runing as www-data user use command sudo crontab -u www-data -e for editing
after save crontasks will be installed automaticaly.
OR
You can create tmp_crontask_file with content * */2 * * * php -f /var/www/html/script.php > /dev/null 2>&1 AND next use sudo crontab tmp_crontask_file for install cron(s) from file (as root) sudo crontab -u www-data tmp_crontask_file (as www-data user).
Edit 1:
WARNING!
If you install cron from file (last option) content of file overwrite existing crontab.

Laravel scheduler not working

I have a Laravel 5 application where i want to run cronjobs, i have created a command, that will be running every 5 minutes.
But for some reason it´s never called.
I have added the following crontab.
* * * * * php /var/www/vhosts/website.com/httpdocs/artisan schedule:run
I checked the cron log file, and it looks like it´s running:
Apr 15 10:19:01 lvps92-51-xx-xx CROND[15420]: (root) CMD (php /var/www/vhosts/website.com/httpdocs/artisan schedule:run)
But it is never calling the command.
The funny thing is that if i run the command manually its working...
[root#lvps92-51-xx-xx /]# php /var/www/vhosts/website.com/httpdocs/artisan schedule:run
Running scheduled command: (touch /var/www/vhosts/website.com/httpdocs/storage/framework/schedule-c56ad4a76ba9d8e31def649e20c42f73; /usr/local/php566-cgi/bin/php artisan test:run;
rm /var/www/vhosts/website.com/httpdocs/storage/framework/schedule-c56ad4a76ba9d8e31def649e20c42f73) > /dev/null 2>&1 &
There is no logging entries in the Laravel Log.
(I know that i run the cronjob as root, but that was to avoid permissions errors doing testing)
Laravel version: 5.0.27Server: Centos 6
What am i missing?
I also had this problem few days ago and this is how I solved it.
I am actually using hostmonster for hosting my application.
My cron job runs every minutes.
* * * * * /usr/local/bin/php path/to/artisan schedule:run 1>> /dev/null 2>&1
Hope this helps
Found out what was wrong, i have more than 1 PHP version installed and for some reason cron is using the default php installation even when i have added the new PHP path to .bash_profile.
I fixed it by adding path to the right PHP version:
* * * * * /usr/local/php566-cgi/bin/php /var/www/vhosts/website.com/httpdocs/artisan schedule:run 1>> /dev/null 2>&1
That way its forced to run with that PHP version.

How to set cron in to run PHP file on localhost in Ubuntu?

I want to execute a PHP script on my localhost in Ubuntu. I have tried a lots of methods to apply cron but no luck!
We can set cron on our localhost through following steps:
Open crontab in your terminal:
EDITOR=gedit crontab -e
Add your cron settings at the end of your file (we are setting cron to be execute in every 2 minute in our example):
*/2 * * * * /usr/bin/php -q /path/to/phpfile.php > /dev/null
Save your cron file and run:
sudo service cron restart

Categories