How can I setup cron / task scheduler with Laravel (PHP) ?

garyworksHOBBY

a year ago

Hi,

I am using Laravel 11 and I know normally when I setup on a VM, I need to setup a cron entry like this:
https://laravel.com/docs/11.x/scheduling#running-the-scheduler

How can I do this in Railway's way?

Thanks.

1 Replies

garyworksHOBBY

a year ago

I found an alternative way to do this, so I left it here for reference.

https://www.lamadly.com/articles/how-to-set-up-cron-job-in-railway-app

You may create a separate nodejs script from the root folder. (eg. cron.js)
Use it to run node-cron and shelljs and call the 'php artisan schedule:run >> /dev/null 2>&1' command

Add a "Custom Start Command" command under the "Deploy" section of your service
e.g. "node cron.js"
Then it should run your Laravel schedule task just fine.

I haven't found a native way to do this yet, but at least it's working now.


How can I setup cron / task scheduler with Laravel (PHP) ? - Railway Help Station