cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring cron job for siteground

SOLVED

Configuring cron job for siteground

I am using siteground for hosting and I need some help with the proper syntax to run the indexer: reindex for magento 2. They use linux with which I am totally unfamiliar. Any help would be appreciated.

4 REPLIES

Re: Configuring cron job for siteground

If your hosting provider uses cPanel, you should be able to use the following Cron Job:-

php /home/<CPANEL USERNAME>/public_html/bin/magento cron:run
php /home/<CPANEL USERNAME>/public_html/update/cron.php
php /home/<CPANEL USERNAME>/public_html/bin/magento setup:cron:run

Where <CPANEL USERNAME> will be the username for your cPanel account. This also assumes that your Magento store is in the "public_html" directory. If it is in other directories, do add them in after "public_html". 

 

Some hosting providers may also use a different path to the PHP binary so you may need to double confirm with your provider on whether you can use just php or if you will need something else (like /usr/bin/php).

 

The first command (magento cron:run) will perform the reindex, send automated e-mails, generates the sitemap, etc. 

 

The other two commands are used by the Component Manager and System Upgrade.

 

James Lee | Moderator • Magento Master
See My Recommended Magento Hosting & Security Tips

Re: Configuring cron job for siteground

FYI, there is a small error in your cron commands. The -c flag is only needed if you specify a custom php.ini path, so the following should suffice:

 

php /home/<CPANEL USERNAME>/public_html/bin/magento cron:run
php /home/<CPANEL USERNAME>/public_html/update/cron.php
php /home/<CPANEL USERNAME>/public_html/bin/magento setup:cron:run

If you want to discard any output from the cron scripts you can add >/dev/null 2>&1 at the end of each command. This can be useful if you don't want to receive an email notification each time the cron runs.

Sindre M, CEO & Founder
ProperHost.com - The Magento Hosting Experts

Re: Configuring cron job for siteground

@SindreM: Thank you for pointing that out. I've updated my post now. Smiley Happy

 

I forgot to remove the -c flag which is included in Magento's default Cron Job syntax while I was modifying it to be usable in cPanel. 

 

As for >/dev/null 2>&1, good point on that but if the user is running cPanel and do not want to receive any Cron emails, I'll generally just recommend that they input a blank email address into cPanel's Cron Job page so the Cron Job email feature will be disabled. 

James Lee | Moderator • Magento Master
See My Recommended Magento Hosting & Security Tips

Re: Configuring cron job for siteground

This worked for me after hours of trying....

* * * * * /usr/bin/php-cli /home/<CPANEL FTP USER NAME>/public_html/bin/magento setup:cron:run >> /home/<CPANEL FTP USER NAME>/public_html/var/log/setup.cron.log

* * * * * /usr/bin/php-cli /home/<CPANEL FTP USER NAME>/public_html/update/cron.php >> /home/<CPANEL FTP USER NAME>/public_html/var/log/update.cron.log

* * * * * /usr/bin/php-cli /home/<CPANEL FTP USER NAME>/public_html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /home/<CPANEL FTP USER NAME>/public_html/var/log/magento.cron.log

SWAP THIS FOR YOUR FTP USER NAME <CPANEL FTP USER NAME> AND CHECK THE FILE PATHS ARE ALL OK