Frezka SaaS - Documentation

How to setup Server Cron Job for Laravel (Frezka SaaS)

This guide provides step-by-step instructions to set up the required cron jobs on their server for Frezka SaaS (Laravel Task Scheduler).

Frezka utilizes Laravel’s built-in scheduler to manage background processes such as:

1. Google Calendar Syncing (runs every 5 minutes).

2. Background Queue Processing (processes emails, notifications, and heavy jobs).

3. Subscription Checks (handles billing/expiry).

The Golden Rule of Laravel Scheduling

Instead of creating multiple cron entries for each task, Laravel requires you to set up only one single cron job on your server that runs every minute. This job executes the Laravel Scheduler, which then handles all sub-tasks automatically.

The cron command looks like this:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Method 1: Setting up Cron Job via cPanel (Shared Hosting)

Most Envato clients host their websites on shared hosting using cPanel. Follow these steps to configure the cron job:

1. Log in to your cPanel.

2. Scroll down or search for the Advanced section, then click on Cron Jobs.

3. Under the Add New Cron Job section:

  • Common Settings: Select Once Per Minute (* * * * *) from the dropdown. This automatically fills all time fields (Minute, Hour, Day, Month, Weekday) with asterisks *.
  • Command: Enter the command to run the scheduler. You must specify the full absolute path of your project.
    bash cd /home/yourusername/public_html && php artisan schedule:run >> /dev/null 2>&1
    (Be sure to replace /home/yourusername/public_html with the actual path to your Frezka installation directory).

4. Click Add New Cron Job.

[!TIP]
Finding your PHP Path:
On some shared hosting servers, using php directly in the command may invoke an outdated system PHP version instead of the version your project uses (e.g. PHP 8.2). If your cron job fails to run, find your server’s PHP binary path (usually shown on the cPanel homepage or via search) and prefix the command with it:
/usr/local/bin/ea-php82/php-cli artisan schedule:run >> /dev/null 2>&1

Method 2: Setting up Cron Job via SSH / Linux Terminal (VPS/Dedicated Server)

If you are running the project on a VPS (like Ubuntu, CentOS, or Debian) with terminal access:

1. Connect to your server via SSH.

2. Open the crontab configuration file for the web server user (usually www-data or nginx):

   sudo crontab -u www-data -e

(If running as a regular user, you can just run crontab -e).

3. Add the following line at the very bottom of the file:

   * * * * * cd /var/www/frezka-saas && php artisan schedule:run >> /dev/null 2>&1

(Be sure to replace /var/www/frezka-saas with your actual project directory).

4. Save and exit the editor (for nano, press Ctrl + O, Enter, then Ctrl + X).

Method 3: Cloud Panels (RunCloud, CyberPanel, aaPanel, Forge)

If you are using a modern cloud server control panel:

1. Navigate to your Web App / Site settings.

2. Find the Cron Jobs or Task Scheduler menu.

3. Add a new cron job with the interval set to Every Minute (* * * * *).

4. Set the command:

   php /path-to-your-project/artisan schedule:run

5. Choose the appropriate PHP version (e.g., PHP 8.2) in the panel dropdown if prompted.

Crucial Note: Queue Connection (QUEUE_CONNECTION)

If you set QUEUE_CONNECTION=database in your .env file (instead of sync), Laravel requires a background process to run the queue.

Typically, this requires installing Supervisor on a VPS. However, since many users use shared hosting (where Supervisor is not available), Frezka SaaS has a built-in scheduler command in app/Console/Kernel.php that automatically executes and manages the queue worker:

$schedule->command('queue:work --tries=3 --stop-when-empty')->withoutOverlapping();

Because of this built-in scheduler command, once you set up the single schedule:run cron job, it will automatically start and run the queue worker for you! No additional Supervisor installation is required on shared hosting.

Troubleshooting Checklist

1. PHP Version Mismatch: If your scheduler isn’t working, verify that your command line PHP version matches the web PHP version (Frezka requires PHP 8.1+ / 8.2+).

2. File Permissions: Ensure the directory /path-to-your-project/storage and /path-to-your-project/bootstrap/cache are writable by the cron process.

3. Execution Output Logs: For debugging, instead of sending output to /dev/null, you can write it to a log file to see any errors:

   cd /path-to-your-project && php artisan schedule:run >> storage/logs/cron.log 2>&1

Check storage/logs/cron.log after a minute to see if the job ran successfully.