I'm running a Digital Ocean's Ubuntu 16.10 x64 and have deployed the php Framework Laravel 5.3.28 on the server.
For the most part everything is working as normal however I'm trying to get the crontab to call artisan commands like php artisan schedule:run so that laravel's task scheduler can be put to use.
I do not wish to download any extra packages to make this work as I feel there shouldn't really be a need to since the cron can call, what looks like, any command if properly coded.
What I'm trying to do:
From within the crontab -e I'm trying to properly write the Ubuntu correct way to call php artisan schedule:run
What I've done:
I've currently tried multiple different ways of writing this command and nothing is working as noted below:
#Attempt for cron
SHELL=/bin/bash
#PATH=????? <---Confused if this is even needed
* * * * * php /path/to/artisan scheduled:run 1>> file.log 2>&1
* * * * * /path/to/php artisan scheduled:run 1>> file.log 2>&1
* * * * * /path/to/php artisan scheduled:run >> file.log
* * * * * /path/to/php artisan scheduled:run 1>> file.log
* * * * * /path/to/php artisan schedule:run
* * * * * /path/to/php /path/to/artisan scheduled:run 1>> file.log
I've gone to multiple resources to try and find the answer but nothing seems to be the answer to my specific problem.
Resources:
https://laracasts.com/series/intermediate-laravel/episodes/2?autoplay=true
http://laravel.io/forum/03-05-2014-automated-mysql-backups?page=1
https://laracasts.com/discuss/channels/laravel/setting-up-larvel-cron
https://community.centminmod.com/threads/how-to-run-a-cron-job-properly.2287/
https://laravel.com/docs/5.3/scheduling
https://laracasts.com/lessons/recurring-tasks-the-laravel-way
https://laracasts.com/index.php/discuss/channels/laravel/laravel-artisan-commands-trough-cron-tab
https://deploybot.com/guides/deploy-a-laravel-app-to-digitalocean
Conclusion:
At this point I'm stuck beyond stuck. Can someone please help me? All I'm trying to do is call the php artisan command using Ubuntu's cron and I don't know the exact way to do it. ANY and all assistance is greatly appreciated.
Thanks in advance,
Happy Holidays!!
Here we go. That's how mine looks like. :)
* * * * * php /home/spacemudd/laravel/artisan schedule:run >> /dev/null 2>&1
Several of your crontab entries should work. If they appear to not be working the next question is whether you have installed the php-cli package? Without it you will not be able to run php scripts from the command line, only via a web server. If you haven't already I would recommend installing php7.0-cli via:
sudo apt-get update
sudo apt-get install php7.0-cli
The case could be made that when you downloaded php7 via sudo apt-get install php7.0-fpm it downloaded a version that would work with Laravel 5.3 but not necessarily for cron jobs calling php commands with Ubuntu. This is a hypothetical though and I feel might still be worth investigating.
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/
The below cronjob is not working, although the task itself is working when I manually run it using php artisan q:calc .
I just added the path for php and artisan files as shown below, and pasted the command in the terminal.
Am I missing something ?
* * * * * /usr/bin/php /var/www/html/sharp/artisan schedule:run >> /dev/null 2>&1
That command is a cron entry, not something you run in terminal.
For example, under the specific user you would run (depending on your environment):
$ crontab -e
And paste the above to the crontab file.
You can learn more in the docs:
https://laravel.com/docs/master/scheduling
Or by researching how to add cron entries for your specific operating system.
While trying to execute a cron job using Laravel's scheduler, I get in the logs file that the commands are executing with php7 and php7.1 which is weird! can anybody explain what's happening?
Here is a screenshot of the content of the log file:
My crontab file looks like:
* * * * * cd /var/www/ && php /var/www/artisan schedule:run >> /var/www/storage/logs/cron.log 2>&1
You can force specific version to be used by modifying your cron to:
* * * * * cd /var/www/ && /usr/bin/php7 /var/www/artisan schedule:run >> /var/www/storage/logs/cron.log 2>&1
It could be that the cron is getting confused with which version of PHP to use since you have multiple versions installed.
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.
I added a cronjob by entering this command - crontab -e. I added the following tasks in that file-
*/5 * * * * /var/www/web/vendors/shells/aggregated_deals.php
*/5 * * * * /var/www/web/vendors/shells/deals.php
These are php scripts. after that i restarted the apache server,but these scripts are not executing. And syslog log file is empty.
please help me to run this cron.
I don't think that will run by itself - you need to run the scripts using the PHP interpreter, like this:
/usr/bin/php /var/www/web/vendors/shells/aggregated_deals.php
Note that your installation may have php elsewhere - use the command which php on the command line to find out the location.
I don't think you can execute a PHP file by calling it like that, I always use a curl:
*/5 * * * * curl http://domain.com/page
Or I guess you could run it using the php command itself if you don't want to use the web server:
*/5 * * * * php /var/www/web/vendors/shells/aggregated_deals.php
What ever you type after the stars in the crontab rule will be the command execute against the system. If you run the command "/var/www/web/vendors/shells/aggregated_deals.php" in terminal I bet nothing happens...you need to invoke this as a PHP script.
Why don't you call php-cli with the right user ?
*/5 * * * * www-data php /var/www/web/vendors/shells/aggregated_deals.php
OR
*/5 * * * * root /usr/bin/php /var/www/web/vendors/shells/aggregated_deals.php
Or something like that.
Have you already installed php-cli ?
First, you need to make sure that you have PHP CLI available. You can do it by running this:
$ php -v
If you see some sane output, then PHP CLI is available. Otherwise you'll need to install it. Installation depends on the distro you're using.
Second, if you want to run CLI scripts directly, you need to make them executable:
$ chmod +x /var/www/web/vendors/shells/aggregated_deals.php
$ chmod +x /var/www/web/vendors/shells/deals.php
Third, PHP CLI scripts are not related to apache and you don't need to restart it to make CLI scripts work.
You need to tell the server to execute the files with PHP. Do all the stesps as described in Elnurs answer, and put these as your lines in cron:
*/5 * * * * php -f /var/www/web/vendors/shells/aggregated_deals.php > /tmp/my.log 2>&1
*/5 * * * * php -f /var/www/web/vendors/shells/deals.php > /tmp/my.log 2>&1
If that doesn't work you may need to include the entire path to PHP.
I've also just added some lines to make the script log any output.
You need to run it cake style... you must run
cake shellName shellParam
i your case it would be
cake aggregated_deals > /tmp/my.log
cake deals > /tmp/my.log 2>&1
this cake is in your cake folder, and you should be running it from your app folder... i am not sure how to do this from cron but that is what you have wrong...
This is asuming those scripts are valid cakeShells
You need to tell the server to execute the files with PHP. Do all the stesps as described in Elnurs answer, and put these as your lines in cron:
*/5 * * * * php -f /var/www/web/vendors/shells/aggregated_deals.php > /tmp/my.log 2>&1
*/5 * * * * php -f /var/www/web/vendors/shells/deals.php > /tmp/my.log 2>&1
$ chmod +x /var/www/web/vendors/shells/aggregated_deals.php
$ chmod +x /var/www/web/vendors/shells/deals.php
I know this is posting a long time after, but it looks like i'm not the only one.
Anyway my suggestion would be to add the path to the php in the cron line:
*/5 * * * * /usr/bin/php -f /var/www/web/vendors/shells/aggregated_deals.php > /tmp/my.log 2>&1
*/5 * * * * /usr/bin/php -f /var/www/web/vendors/shells/deals.php > /tmp/my.log 2>&1
Again make sure the permissions are good