Laravel scheduler @ docker & cPanel

Every time we deploy a new Laravel application & it has a scheduled command, the first thing to setup even on testing environment, to setup the scheduler.

The amazing Laravel documentation write it properly, but this could be a shorter and +1 version of it.

Basic + cPanel version

First of all, on a basic server setup, you just have to use the following command with the proper path:

* * * * * cd /home/userfolder/laravel-application && /usr/local/bin/php artisan schedule:run > /dev/null

On a proper cPanel site, you have cron option, so you just need to add the command above (with proper path).

Docker version

If you are like me, you have a basic VPS setup, installed with docker. Then you have a lot of docker container, which could work standalone. Here comes the trick, when you want to run the Laravel scheduler. You can find a few setup, which explains, how to add this scheduler to the container.

Instead, I prefer the following way:

  • setup the cron on the host machine
  • edit the VPS default cron file ( /etc/crontab )
  • Add the following line to it:
* * * * * root docker exec -i Container_Name php /var/www/html/artisan schedule:run >> /dev/null 2>&1

That's all!

Have a nice day!

© 2024 PappZ. All rights reserved.