PHP-CLI Command Not Found - laravel

Now I just moved to inmotion from siteground and previously from bluehost. I am trying to set up my laravel(lumen) application on the server. I have been able to get everything else working but the scheduler which I just cannot seem to get to work.
This is the cron job php -q /home/xxxxx/xxxxx/artisan schedule:run which seem to run fine however it fails to execute the queue:work command.
I noticed on my previous hosting I had to edit the Illuminate\Console\Scheduling\Scchedule.php file like this:
return $this->exec("php-cli /home/xxxxx/xxxxx/artisan {$command}", $parameters);
using the regular php command did not work for some reason I had to use php-cli, however with my current hosting it says "command not found" whenever I try to use the php-cli command manually and all my cron job returns in my email is this:
Running scheduled command: php-cli /home/xxxxx/xxxxx/artisan queue:work > '/dev/null' 2>&1 &
I would like to know how I can fix this and get the scheduler to work.
Yes I have php installed. (v7.0)
Yes I have the php-cli package installed. (v7.0)
My VPS server uses linox OS.

You do write absolute route to php-cli command and artisan script to properly work:
/usr/local/php70/bin/php-cli /home/{username}/{path-to-app}/artisan schedule:run >> /dev/null 2>&1

Related

Laravel Cron Job not running over ubuntu server

I have a laravel application setup over Ubuntu server using Nginx. Here I have the cron jobs. I was facing an issue, that the server was not automatically picking up changes on Jobs Files. So I googled the things, and found a command from this article which I ran;
php artisan queue:restart
Since I have run this command, now no job is running even. I am also trying with simple HeartbeatJob to log info but it is also not working. When I do php artisan schedule:run,
no error in particular just screen output as:
[2021-09-11T08:41:32+00:00] Running scheduled command: App\Jobs\Heartbeat
But nothing happens. Any idea what this queue command has done wrong and how I make my jobs working again?
Your cron job will need the absolute path to artisan, so should look something like :
php /home/user/site.com/artisan queue:restart
You may also need to specify the queue with :
php /home/user/site.com/artisan queue:restart --queue=nameofqueue

How to automatically call laravel cron jobs while website is running

I am working with task scheduling in laravel. It's working well by using artisan command in cmd. But what's the problem with automatically calling the task on server. It's not running every minute.
https://laravel.com/docs/8.x/scheduling#running-the-scheduler
You will need to setup a cron job on your server that calls your scheduler
If you using Laravel Scheduler, you have to access in your server via ssh.
ssh user#<IP-address>
edit crontab file to call every minute php artisan schedule:run artisan command.
So:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
If it not start,try to restart the web server. If you are using nginx, for ex.: sudo systemctl restart nginx

Laravel Forge Scheduler - Run Command

When using Laravel Forge's scheduler, you can trigger all the cronjob by e.g. running:
php /home/forge/default/artisan schedule:run
However, when wanting to execute a sole command, it will fail and says "fatal: not a git repository (or any of the parent directories): .git".
Via SSH, I would execute the command like this:
ssh to the server
cd path/
php artisan command:name
So how would I declare it in Laravel Forge's scheduler?
php /home/forge/default/artisan command:name
Does not work.
The solution is simply to remove the slash after /path/artisan - it is /path artisan.

Cronjob setup for laravel 4.2 in cpanel

I am using laravel 4.2. I have created command file for cron job and added it into artisan file. I tested it in command. Everything is working fine in localhost. In Cpanel server I gave command path like,
php /home/fridayburr/public_html/version1/artisan active:user 1>> /dev/null 2>&1
But cron job is not working.
This is how I did in my shared Hosting using CPANEL
Here CRON Task is set on UNIX, to run every minute.
Add the schedule call with appropriate time schedule.
laravel Schedule documentation

Laravel php artisan serve logs stored and start artisan serve automatically

id like to know :
Where Laravel php artisan serve command logs stored ?
How to automatically start php artisan serve when sever (Apache) starts ?
Laravel logs are stored at storage/logs
You don't need artisan serve, if you have Apache handling your HTTP traffic.
To the first question
Where Laravel php artisan serve command logs stored ?
Laravel server logs are stored in storage/logs folder ,which contains files for the server logs
To the second question
How to automatically start php artisan serve when sever (Apache) starts ?
If you need to automatically ,A very simple way to do this would be to use use laravel scheduling Artisan Commands using cron
Ensure cron is installed yum install vixie-cron (assuming you use centos). Start it with service crond start
Add laravel Schedule object vi /etc/crontab and add * * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1 ,to the cron schedule file .
Go to app/Console/Kernel.php file and add $schedule->command('foo')->withoutOverlapping(); where foo is the artisan command you would like to run in this case serve , so it should be $schedule->command('serve')->withoutOverlapping();
Restart cron deamon with service crond restart.
See this related question https://stackoverflow.com/a/34096590/1226748
I would definitely recommend NOT using artisan's server in production like EVER, it's for testing only. -- You would be WAY better off to use nginx as a reverse proxy and you can set whatever port you want that way, and have your angular app still connect to it.

Resources