Laravel Forge Scheduler - Run Command - laravel

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.

Related

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

PHP-CLI Command Not Found

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

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.

Laravel Envoy on fortrabbit

I've setup a Laravel app on a Fortrabbit server. I can do the following
$ ssh user#server
$ cd htdocs
$ php artisan migrate
Which works perfectly fine.
But I'm trying to use Envoy for tasks like this. So I've made a simple task:
#servers(['test' => 'user#server'])
#task('task:test', ['on' => 'test'])
cd htdocs
php artisan migrate
#endtask
However, I encounter the following issue when doing so:
$ envoy run task:test
[user#server]: \(><)/ Welcome to the rabbit hole. \(><)/
[user#server]: [PDOException] SQLSTATE[HY000] [2002] No such file or directory
It might be worth noting that the db connection uses credentials from ENV variables set in the Fortrabbit interface. If i SSH into the server and do env, all the variables are listed as they should be. But when doing
$ ssh user#server env
I only get a small portion of the Fortrabbit server ENV variables.
I can't figure out what could be the cause of the error, and I haven't been able to find anything when asking Google. Could anybody shed a bit of light on this? Thanks alot.
As #ukautz said, the session scripts are not executed by envoy, that's why some of your environment variables are missing.
Here's what I did:
#servers(['dev'=>"<<user#server>>"])
#task('list')
. /etc/profile.envvars
env
#endtask
That showed all ENV variables, including those set by you on the dashboard !
Your script should work with this:
#servers(['test' => 'user#server'])
#task('task:test', ['on' => 'test'])
. /etc/profile.envvars
cd htdocs
php artisan migrate
#endtask
I suggest to check if your environment dedection works as expected.
$ php artisan env
If not, your can force the environment for artisan commands, like so:
$ php artisan migrate --env=test_server

Resources