Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stratboy's avatar

How to use crontab in Herd?

Hi, I'm quite new to this thing of the cron jobs. I'm currently using Docker desktop but found out that to do a 'simple' thing like setting a cronjob, I have to go to the moon and back. So I'm thinking to change development environment. I thought of Herd, since it should be more simple to manage than a dockerized app, and more similar to the everage production environments.

Anyway, on a test Herd site, if I open the Terminal and write crontab -e, the following is the output:

crontab: no crontab for [user] - using an empty one
crontab: code -w: No such file or directory
crontab: "code -w" exited with status 1

If I take a look to the /etc dir, there is no crontab file.

What should I do?

0 likes
4 replies
LaryAI's avatar
Level 58

To set up and use crontab in Herd, you need to ensure that the cron service is installed and running, and that you have the necessary permissions to edit the crontab file. Here’s a step-by-step guide to help you set up a cron job in Herd:

  1. Install Cron: First, make sure that the cron package is installed on your Herd environment. You can install it using the package manager. For example, if you are using a Debian-based system, you can use apt-get:

    sudo apt-get update
    sudo apt-get install cron
    
  2. Start the Cron Service: After installing cron, you need to start the cron service and ensure it runs on system boot:

    sudo service cron start
    sudo systemctl enable cron
    
  3. Edit the Crontab: Now you can edit the crontab file for your user. The error you encountered suggests that the default editor is not set correctly. You can set the default editor to nano or any other text editor you prefer:

    export VISUAL=nano
    export EDITOR=nano
    

    Then, edit the crontab file:

    crontab -e
    
  4. Add a Cron Job: In the crontab file, you can add your cron job. For example, to run a script every day at midnight, you would add:

    0 0 * * * /path/to/your/script.sh
    
  5. Verify the Cron Job: To verify that your cron job has been added, you can list the current cron jobs:

    crontab -l
    
  6. Check Cron Logs: If your cron job is not running as expected, you can check the cron logs for any errors. The logs are usually located at /var/log/cron.log or /var/log/syslog depending on your system configuration.

    sudo tail -f /var/log/syslog
    

By following these steps, you should be able to set up and manage cron jobs in your Herd environment. If you encounter any specific errors or issues, feel free to provide more details, and I can help troubleshoot further.

Snapey's avatar
Snapey
Best Answer
Level 122

You can run php artisan schedule:work. This is a long running task and will process the schedule every minute.

Its designed to give the same effect as cron job in a local environment.

1 like
stratboy's avatar

@Snapey yes, I was convinced that I had to learn more of Docker, but since in production environment I'll probably be running cron jobs differently, it make sense not to worry too much on how I run them locally. Thank you.

Please or to participate in this conversation.