How To

How to set up Cron for Magento 2 on Amazon AWS

It is impossible if you are using Magento 2 and you are not familiar with Cron job because it is only hands-on functionality that allows you to automate your task and schedules. Basically, Cron job is a feature offered by Linux that contains a bunch of commands or a script that runs frequently. Due to its automation facility, it helps a lot to save time and efforts of store owner instead of manually doing a task which makes it the perfect choice for repeated tasks.

Generally, this Cron job can help to scheduled various tasks like reindexing, generating emails, generating newsletters, sitemaps and more. In Shared hosting, you can easily add Cron Jobs using Cron Job Manager from Cpanel but in Cloud Servers, you don’t have CPanel access. So, you have to use CLI (Command Line Interface) to write Cron Jobs using SSH.

Here are few steps to set up your own Cron Jobs on AWS EC2 Server within minutes.
Firstly open your SSH with your credentials and type below command to open an editor.

crontab -e

Now, you will get some of the existed editors options to open, select the second one.

  1. /bin/ed
  2. /bin/nano
  3. /usr/bin/vim.basic
  4. /usr/bin/vim.tiny

After that type following command to your editor.

*/5 * * * * /usr/bin/php /home/magecomp/www/bin/magento cron:run > /home/magecomp/www/var/log/magento.cron.log&

*/5 * * * * /usr/bin/php -c /etc/php5/apache2/php.ini /home/magecomp/www/update/cron.php > /home/magecomp/www/var/log/update.cron.log&

*/5 * * * * /usr/bin/php /home/magecomp/www/bin/magento setup:cron:run > /home/magecomp/www/var/log/setup.cron.log&

Note: You need to replace your php path with “/usr/bin/php” to above command.
To find your php installation path run command “which php”.
You need to put your Magento 2 root path instead of “/home/magecomp/www
You can find it by using “pwd”.

Lastly, Saved the editor with “ctrl+x” and then press Y.
You have successfully created Cron.

To get a list of created Crons, type below command in your SSH Console.

crontab -l

Besides that here are some of the examples that can help you to set your own Cron job according to your business needs.

Cron Expression Examples:
* * * * * –> Run every minute. ex: for 15 mins => */15 * * * *
0 * * * * –> Run on the hour, every hour ex: every 3hrs => * */3 * * *
0 21 * * * –> Run at 9 p.m. every day
0 0,12 * * 6 –> Run at midnight and midday every Saturday
45 3 */2 * * –> Run every second day at 3.45 a.m.

What starts stand for?
1st star: Minute (ranges from 0-59)
2nd star: Hour (ranges from 0-23)
3rd star: Day (ranges from 1-31)
4th star: Month (ranges from 1-12)
5th star: Day-of-week (0-6 –> 0- Sun. 1-Mon, 2-Tue…etc)

Tadaa! Now you did it.
Lastly, hit that stars if this blog worked for you & comment down below if you faced any issue.
Happy Croning!

Click to rate this post!
[Total: 10 Average: 4.9]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

13 hours ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

3 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

3 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

4 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

4 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

7 days ago