Rafael Padovani
Rafael Padovani

Reputation: 95

How to Set Up a Cronjob to Reindex Magento 2 inside Docker

I'd like to know how to set up a cron job to reindex Magento 2. I have installed crontab in my docker by running

apt-get install cron

inside my php container, then I run

crontab -e

and I'm able to see and edit my cronjob file. So I set up a command to execute every minute like this:

* * * * * php bin/magento indexer:reindex

I close the editor and says that a new crontab was installed. I run crontab -l, and indeed my command is there, but nothing happens. What is missing?

Upvotes: 2

Views: 2083

Answers (1)

Sérgio M.
Sérgio M.

Reputation: 1297

First mistake is the path, you need to type the full path for your commands.

For instance, php is usually located at /usr/local/bin/php but you make sure of this by running which php inside your php container. For the bin/magento path you can just enter bin folder and type pwd and get the full path.

The second mistake is that you might beeing forgetting to start the cronjob by running service cron start. Also you can check status at any time with /etc/init.d/cron status

Upvotes: 2

Related Questions