Help, unable to set up server cron for a plugin

Joined
Sep 12, 2016
Messages
28
Likes
4
Degree
0
Hi, I'm trying to install a cart recovery plugin on my woocommerce site
For that, I have to set up a server cron( for it to execute the task(send recovery mail) without the need for someone to visit the site)

Now, in the doc from the plugin it says how to set it up using a cpanel like hostgator; my site doesn't have one, it on a linode VPS server using NGINX, PHP7, and Ubuntu 16.04 LTS

The plugins guide for setting it up says:

How to set up a Server Cron using CPanel such as HostGator
1. disable wp-cron by adding this line define('DISABLE_WP_CRON', true); in wp-config.php
2.Add New Cron Job:
wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
3.Please Note: If you use some security plugins, those plugins might restrict this wget command by writing mod_rewrite rule in .htaccess file. Like this RewriteCond %{HTTP_USER_AGENT} ^Wget [NC,OR] Remove this line in order to make server cron work. Please keep in mind the security implications of this change.

So I've done 1 and 2 and can't get it to work, there has to still be someone on the site for the cron job to execute and the mails are not being sent until that happens.
Yes, the step #2 using crontab -e on my server and adding this line(i have https):
*/2 * * * * wget -q -O - https://myrealsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

For it to execute the server cron every 2 minutes as I also put in my plugin settings, so maybe there is something I am missing to set up or did wrong - it is not a cpanel on hostgator- (asked the plugin developer and said it should work if you follow the guide, so ask my host) I don't have a .htaccess so can't check step #3

Any help from you; server lords, cron job slayers will be appreciated!
Thanks
 
You should really get a server admin (@SmokeTree is my go to recommendation) to handle this, but this is less than 3 minutes worth of work. I'm assuming you are on Ubuntu:

1. Login to your server through SSH. <- If you don't understand what this means, you need a server admin to do the cronjob update, cause you can seriously mess something up as root.

2. run the command "cronjob -e" <- that edits the cronjob lists (you may have to sudo to root if the cronjob requires you to run as root).

3. Add the cronjob line at the end of the file while you are in the text editor (nano is the best - it may ask you to choose a text editor if it's your first time running "cronjob -e").

4. Save the new cronjob by pressing ctrl+o. Hit "Enter" to save.

4A. Here you'll run into a problem if you aren't root and you are attempting to save a root cronjob. It will say permission denied. You'll have to exit (ctrl + x) and run the cronjob command as root: "sudo cronjob -e"

4B. Since you are trying to run as root with the "sudo" command, the system will prompt you for your password again. Input it, and you'll have to do step 4 again. This time you shouldn't get a permission denied problem.​

5. Exit, by pressing ctrl + x.

6. Run the command "cronjob -l" to see a list of your cronjobs.

7. Enter the following command to restart cronjobs: "service cronjob restart"

That will restart the cronjobs. Since it is set for 2 minutes you should get an email I guess every 2 minutes (Not sure exactly what that php script does)​

--

Again, I highly recommend getting a server admin to do this for you. If you don't know what you are doing in the commandline and are running as root you can destroy the Earth! (think I'm joking, look at Venus, that's the result of one messed up comandline command - JUST ONE!)
 
Try running the command by itself that you want cron to run and see what kind of output you get. You are sending STDOUT and STDERR to /dev/null which is suppressing any kind of useful message you'll get about what went wrong (or right). For scripts that almost never fail, that's sometimes OK, but in a lot of cases, you'll want to log errors to a file. You can alter your script to log errors by doing something like this:

Code:
*/2 * * * * wget -q -O - https://myrealsite.com/wp-cron.php?doing_wp_cron 1> /dev/null 2> /var/log/wp_cron_errors.log

This will send STDOUT (general program output) to /dev/null and STDERR (error messages) to /var/log/wp_cron_errors.log Definitely start the troubleshooting process by just running the command first and working from there. Oftentimes the answer will be right there, staring at you in the form of an error message.
 
Again, I highly recommend getting a server admin to do this for you. If you don't know what you are doing in the commandline and are running as root you can destroy the Earth! (think I'm joking, look at Venus, that's the result of one messed up comandline command - JUST ONE!)
hahaha, yep I've messed everything a dozen times a while ago and learned to always make a snapshot so I always can do a backup if anything goes wrong
Also, I use crontab -e (cronjob -e doesn't work) and when i tried to restart the cron using
Code:
sudo /etc/init.d/cron restart
it seemed good, but still can't make it work
Try running the command by itself that you want cron to run and see what kind of output you get. You are sending STDOUT and STDERR to /dev/null which is suppressing any kind of useful message you'll get about what went wrong (or right). For scripts that almost never fail, that's sometimes OK, but in a lot of cases, you'll want to log errors to a file. You can alter your script to log errors by doing something like this:

Code:
*/2 * * * * wget -q -O - https://myrealsite.com/wp-cron.php?doing_wp_cron 1> /dev/null 2> /var/log/wp_cron_errors.log

This will send STDOUT (general program output) to /dev/null and STDERR (error messages) to /var/log/wp_cron_errors.log Definitely start the troubleshooting process by just running the command first and working from there. Oftentimes the answer will be right there, staring at you in the form of an error message.
Tried this, there are no errors shown, sadly I still can't make the plugin work

Even tried it without step #1: disabling wp-cron by adding this line define('DISABLE_WP_CRON', true); in wp-config.php

there need to be someone on the site for it to work properly :mad:
 
Last edited:
Also, I use crontab -e (cronjob -e doesn't work) and when i tried to restart the cron using
Code:
sudo /etc/init.d/cron restart
it seemed good, but still can't make it work

Did you try giving the full path to wget while setting up cron?

If you don't know the full path, you can find it by running:
$ whereis wget
The output should look something like this:
wget: /usr/bin/wget /usr/share/man/man1/wget.1.gz /usr/share/info/wget.info.gz
So, in this case, the path is /usr/bin/wget.

When you add the entry to cron, instead of "wget", use "/usr/bin/wget" (or whatever your path is).

See if it works.

(I actually agree with others - it is better to hire someone to do these tasks - it will save you a lot of time and headache)
 
Holy sh$t plugin is full retarded
Plugin case: It updates the new carts to abandoned after (and then I can send the recovery mail) ONLY when the Admin access the cart list tab on the plugin options and/or Manually updates the cart list tab using an option there; It ruins the whole purpose of the plugin if I need to log in every 10 minutes to update the new carts to abandoned! And ONLY then I'm able to send the recovery mail.
That's why dumbass me was waiting forever for it to send the mail and it just would never happen :mad:
(if you have any idea how could I make it work automatically let me know, just contacted the plugin developer also)

Oh, also because I use an STMP to send my mails and wp-cron / wget doesn't work like that, so when I setup admin emails via postfix this got fixed :wonder:
 
Last edited:
Back