I have been pulling my hair out for the past 5 hours over what I thought would be a simple task, enabling the cron feature for Laravel. I am running Laravel 5.1 on an Amazon EC2 Ubuntu LAPP stack server.
I have added the cron task to the cron jobs list using the command
sudo crontab -e
Then I have added the command listed in the laravel documentation
* * * * * php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1
I have made sure that cron is running and I can see that the task is running if I run
sudo grep -i cron /var/log/syslog|tail -3
Which returns
Mar 4 15:36:01 ip-172-31-7-174 CRON[15120]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
Mar 4 15:37:01 ip-172-31-7-174 CRON[15123]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
Mar 4 15:38:01 ip-172-31-7-174 CRON[15125]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
I have tested that the path has not got any typos in it by running the command from the command line and it works properly
php /home/bitnami/htdocs/project/app/artisan schedule:run
Also I have added this cron task just to confirm that cron is actualy running
* * * * * echo "Cron" > /home/bitnami/htdocs/project/app/artisan/file.txt
I have also made sure the file is executable by doing the following but this has not fixed the issue either
chmod 755 artisan
chmod 777 artisan (I am aware this is dangerous)
chmod +x artisan (Suggested on fourms)
Does anyone have any suggestions where I'm going wrong here.
I've experienced this and found a solution. It's because of unknown reason in bitnami, so that php command not recognized by cron. I used this command to make it working :
* * * * * /path/to/php/bin/php /home/bitnami/htdocs/project/app/artisan schedule:run 1>> /dev/null 2>&1
Related
I have made a command and scheduled it for every 30 minutes. When I run php artisan schedule:run it works perfectly fine and returns with the expected results, but when I configured it on my live server my cron job do run but instead of retuning the success message it returns with list of all available command in my laravel project. Here is what I am doing.
Command Kernel:
$schedule->command('update:callLogs')
->everyMinute();
Cron Entry:
/usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run
And this is the response I am getting
Laravel Framework 5.8.38
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
(List of all availabe commands)
Any help will be much appreciated.
EDIT
Now my command looks like this
* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan update:callLogs
but getting the same response whereas when I copy the same command and using putty ran the same command and it works perfectly fine. Now it's been a week now and I'm still stuck at this cron thing.
I fixed this by specifying the path to PHP instead of using just php.
From this: cd /home/foobar && php artisan schedule:run
To this: cd /home/foobar && /usr/local/bin/php artisan schedule:run
This stopped me from getting a list of available artisan commands and gave me the right output.
I can see it looks like you've already tried that, but I think others will run into this too. I'd imagine your issue is something to do with the PHP version you're using not being able to properly run PHP scripts. Maybe an opcache thing with CLI?
I faced big challenge as well when I was deploying one my applications, and finally managed to tackle it with:
cd /path-to-project && /opt/cpanel/ea-php71/root/opt/cpanel/ea-php74/root/usr/bin/php-cgi artisan schedule:run
I use Laravel 5.7 for my application
You could try the following code:
* * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1
>> /dev/null 2>&1: we will discard all output of a command.
Can you try the below in cron and share the output of crontab.out
* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/ && php artisan schedule:run >> crontab.out 2>&1
*/30 * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1
OR
*/30 * * * * /usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1
OR
*/30 * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan schedule:run >> /dev/null 2>&1
Also read full post: https://devnote.in/how-to-set-auto-database-backup-with-cron-scheduler-in-laravel/
I am new to Ubuntu server and i install cron job and then make new cron job and no idea why its not working. My application is in Laravel so i have to run artisan command through cron job! When i am in project through root cmd artisan-command run properly but in cron did not run it.
here is my cron job listed
I check the if its running or not like this:
# sudo grep -i cron /var/log/syslog|tail -3
This is the output:
Jan 21 09:30:01 liedergut CRON[5222]:(root) CMD (/path/to/php/bin/php /var/www/html/artisan shows:fetchrss >> /dev/null 2>&1)
Jan 21 09:30:01 liedergut CRON[5223]: (root) CMD (php /var/www/html/artisan shows:fetchrss >> /dev/null 2>&1)
Most certainly /var/www/html/php and /path/to/php/bin/php do not exist. You can find out where the php executable is by using whereis php (as you stated in your comment, it is /usr/bin/php). So to make your artisan command run every minute your cron line should be
* * * * * /usr/bin/php /var/www/html/artisan shows:fetchrss >> /dev/null 2>&1
I would suggest though to run Laravel's scheduler every minute:
* * * * * /usr/bin/php /var/www/html/artisan schedule:run >> /dev/null 2>&1
and schedule your artisan command inside of Laravel, as written on Laravel's task scheduling documentation. This way you can manage your scheduled jobs or re-schedule them without having to edit/touch your crontab.
This command works for me
* * * * * cd /var/www/html/projectname && php artisan schedule:run >> /dev/null 2>&1
I'm have a laravel5.5 project up on shared hosting and trying to run cron job to execute the command "schedule:run" but it just won't execute I think I'm writing the command wrong:
/usr/local/bin/php home/schoolco/prototype/artisan schedule:run >> /dev/null 2>&1
where prototype in the name of my laravel project.
the command works in this directory using ssh.
please if you have any observation or thought share it.
Try like this
/usr/local/bin/php /home/schoolco/prototype/artisan schedule:run > /dev/null 2>&1
And check are you calling right php executable in your terminal with:
$ which php
Maybe it is not /usr/local/bin/php , maybe /usr/bin/php
If your Project is in Root Directory
cd /home/cpanel/public_html && /usr/local/bin/ea-php72 artisan schedule:run >> /dev/null 2>&1
If your Project in a folder within Public_Html then use below
cd /home/cpanel/public_html/folder_name && /usr/local/bin/ea-php72 artisan schedule:run >> /dev/null 2>&1
Hope it will work for you. Thanks
I solved the issue by specifying the php version in the command line:
* * * * * /usr/local/bin/ea-php71 /home/nemanu/root1/artisan schedule:run >> /dev/null 2>&1
I've set up crontab on my AWS-EC2 instance to hit the Laravel scheduling endpoint every minute via the root account using sudo crontab-e:
* * * * * php ~/htdocs/artisan schedule:run >> /dev/null 2>&1
However, despite to the cron logs showing it is indeed running every minute:
Jan 26 12:02:01 ip-172-31-28-116 CRON[5057]: (root) CMD (php ~/htdocs/artisan schedule:run >> /dev/null 2>&1)
the job itself isn't executing.
Running the command php ~/htdocs/artisan schedule:run >> /dev/null 2>&1 straight up triggers the job and works.
I'm really struggling with what is going wrong here, am I missing something?
So, I failed to heed the cron output "No MTA installed, discarding output" - Upon installing an MTA (postfix, via sudo apt-get install postfix), it turned out that for the cronjob, php wasn't findable.
Changing the command to use the output of which php to:
/opt/bitnami/php/bin/php /home/bitnami/htdocs/artisan schedule:run
is now working.
Thanks for your help!
Use absolute paths when adding cron entries. ~/htdocs/artisan that should be set using the full path to your application root directory.
It works when you manually run the command because your environment is set accordingly. Not the case when adding cron entries using sudo.
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.