How to setup cronjob on AWS EC2 Instance Step By Step Solution 2022

    By: Manu
    2 years ago
    Category: AWSViews: 1158

    Ok for this we will setup cron job on a Laravel application.

    To see if Cron Daemon is running run

    sudo service crond status // it will show the status
    

    We need to get into the AWS EC2 instance and then run below given command

    crontab -e
    

    Now an editor window will open to edit this file press "i" key and you will be in insert mode.

    Now add cron job, For example

    0	0	*	*	*	/path/to/php  /path/to/artisan schedule:run >/dev/null 2>&1
    

    Few things to note here

    First five stars what they mean and how can we configure

    Read about this Here

    Now you know about stars, Next thing is to give path to php. you can find php installation using command

    which php // will return path of php
    


    Now path to artisan. so we are setting here laravel application and artisan located in root folder of laravel project so we need to provide that path.

    And then we can run schedule command in laravel using cronjob.


    For getting out of Insert mode Press "Esc" key. and then exit the editor by

    // type
    
    :wq!
    
    //and then hit Enter or Return key
    

    After all setup you can check all cronjobs defined using command

    crontab -l
    


    Hope this helped