Hello Guys,
In this tutorial, we are going to see how we can set up and run crons inside our ddev docker setup for our Magento 2 setup.
In Magento 2 development many configurations need cron for the proper working of your Magento. So crons must be configured properly to ensure our store works properly.
By default, after setup Magento 2 using DDEV, it doesn’t come with crons configured inside our web container.
To cross-verify, Quickly follow the below steps.
- Log in to your web container using ssh
1 |
ddev ssh |
it will log in to ssh of your current project’s web container.
Now run the below command to check if crontab is installed or not.
1 |
crontab -l |
If it shows the above error crontab: command not found it means crontab is not configured in your web container.
Run the exit command to log out from the ssh.
Let’s configure it.
Step 1: Install the DDEV Cron add-on
This DDEV add-on helps to execute a command in the web container based on a cron schedule. Cron is a classic Linux/Unix service with a well-known configuration syntax.
The add-on:
- Installs and runs the cron service inside the web container
- Adds an example job that writes out the current time.
Run the below command to install the add-on in your project.
1 |
ddev get ddev/ddev-cron |
Step 2: Restart DDEV to apply changes:
1 |
ddev restart |
Step 3: Setup Magento 2 Cron Tab in your web server
Run the below commands to install Magento 2 crons:
1 |
ddev magento cron:install |
You can verify entries by running the below command :
1 |
ddev exec crontab -l |
If it shows the entry, you are all set. You can check the cron_schedule table after 1 minute, crons are scheduled now and it will run automatically, all indexers will run on time and consumer queues will work fine on your local system.
Hope this tutorial was helpful. Happy Coding !!
Thanks. See you in the next tutorial.