Learn about Centmin Mod LEMP Stack today
Register Now

Sysadmin Crontab not working for wordpress

Discussion in 'System Administration' started by Lav, Jun 9, 2020.

  1. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    12:41 AM
    1.17.8
    10.3
    I have disabled my cronjob from wp-config and enabled server cronjob but its not working. The automatic update cronjob and every other cronjob of my wordpress site is not working but server cronjob is running very well.
    My crontab -e result is
    PHP:
    13 23 * * * /usr/local/src/centminmod/tools/autoprotect.sh >/dev/null 2>&1
    */* * * /usr/bin/cminfo_updater 2>/dev/null
    22 
    */12 * * * /usr/local/src/centminmod/tools/csfcf.sh auto >/dev/null 2>&1
    0 0 
    * * /usr/local/src/centminmod/tools/cf-authenticated-origin-cert-update.sh update >/dev/null 2>&1
    20 2 
    * * /usr/local/src/centminmod/tools/geoip2db-update.sh >/dev/null 2>&1
    */* * * * sleep 181s wget -- --t 1 http://domain.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
    #0 */8 * * * sleep 179s ;/root/tools/wp_updater_domain.com.sh >/dev/null 2>&1
    27 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
    #*/5 * * * * wget -q -O - http://domain.com/wp-cron.php >/dev/null 2>&1
    Also do I need to put it like
    Code:
    http://domain.com/wp-cron.php
    as
    Code:
    https://domain.com/wp-cron.php
    cause I have selected https as default during vhost configuration.
     
  2. JoeDer

    JoeDer Member

    61
    13
    8
    Feb 22, 2015
    Ratings:
    +38
    Local Time:
    10:11 PM
    Nginx 1.17.x
    MariaDB 10.3.x
    I think you must replace the URL with the full path.
    Code:
    /home/nginx/domains/domain.com/public/wp-cron.php
    
     
  3. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    It should be as https, but it's one reason centmin.sh menu option 22 installs disable wordpress system cronjob as some folks report it not working so you need to test it to see if it works for you. I just use wordpress native cronjob given amount of full page html caching + cloudflare in front of my wordpress sites. So performance shouldn't be a problem.
     
  4. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    12:41 AM
    1.17.8
    10.3
    I have tried every method but none of them working. I used https and also Website Domains Names & Hosting | Domain.com and even tried the way JoeDer said but that's too not working.
    I am using badbot blocker and mod security.
    Can you help me in this?
     
  5. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    would be something you'd need to figure out for your specific usage. If not just use native wordpress cron instead.
     
  6. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    actually looks like updated method at How to Disable WP-Cron (wp-cron.php) for Faster Performance

    so instead of
    Code (Text):
    */5 * * * * wget -q -O - http://domain.com/wp-cron.php >/dev/null 2>&1

    use
    Code (Text):
    */5 * * * * wget -q -O - http://domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

    strange, looking at 123.09beta01 code, centmin.sh menu option 22 already does setup the updated version

    centmin.sh menu option 22 wordpress installs setup cronjob as
    Code (Text):
    */15 * * * * sleep 37 ; wget -O - -q -t 1 http://domain.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

    this has been the way for past 3yrs according to github blame code inspection at centminmod/centminmod

    so maybe you have very old Centmin Mod 123.09beta01 when you created wordpress site via centmin.sh menu option 22 ?
     
    Last edited: Jun 10, 2020
  7. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    12:41 AM
    1.17.8
    10.3
    Hey @eva2000
    Its a two month old stack and yes the default cronjob was in the same pattern as you mentioned. Infact the cronjob is already in the above code but I think you only focused on the lower cronjob which is actually commented out. I am just testing out different types to see which one works cause none of them are working. Not even wordpress cronjob is working after setting false to disable_wp_cron.
    Do you have any other idea as to how write the cronjob so that it starts executing the wordpress. All other server cronjobs are working fine except wordpress.
    If I try to write it like this one
    Code:
    */10 * * * * cd /var/www/example.com/htdocs; php /var/www/example.com/htdocs/wp-cron.php?doing_wp_cron > /dev/null 2>&1
    then what would be the code which will be according to centminmod.
    Also how could I execute cronjob via curl or wp-cli.
    Kindly help as all other method which I have tried are not working.
     
  8. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    you used https domain and not non-https ?
     
  9. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    12:41 AM
    1.17.8
    10.3
    I have tried both but none of them worked.
     
  10. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    could be due to wordpress full page guest HTML caching setup when centmin.sh menu option 22 wordpress auto installer configures caching. So best to just use native Wordpress cron instead of system cronjob as caching is better for performance and gains there are WAY more than using native system cronjobs.
     
  11. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    12:41 AM
    1.17.8
    10.3
    Sorry for all the trouble. Actually it was a plugin 'Social Login for Woocommerce by Xootix' which was messing up with my cronjobs as it was not allowing either wordpress cronjob or server cronjob to execute.
    However I also found out that your default cronjob rule is not executing. So I tried a different code
    Code:
    * * * * * /usr/local/bin/php -q /home/nginx/domains/mydomain.com/public/wp-cron.php > /dev/null 2>&1
    and it is executing every minute. Is this code right for the stack or do I need to change something?
    Also I want to create automatic backup via cronjob via all in one wp migration plugin. Automatic backup is working great via wordpress cronjob but via server cronjob it says it failed to open the file directory for writing. I learnt that file permission of wp-content should be set to 775 recursively for this plugin to execute.
    My question is it safe to set 775 recursively to wp-content and I tried to set it to 775 by chmod 0775 -R but now the new file permission has become 2775 and it is still not granting permission to write. How to fix that?
     
  12. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    ah glad you figured that out !
    Are looking at cronjob logs to see it's executing or are you looking at whether wordpress cronjob tasks are actually running ? system cronjob log showing it executed doesn't necessarily mean wordpress cronjob task is actually ran so you need to verify if it is. That is why I disabled/commented out the system cronjob setup by centmin.sh menu option 22 as folks some reported it working and some reported it didn't. For reliability, I chose to leave it with wordpress native cron system given that there isn't much performance gained using system cronjob if you have guest full HTML page caching in place already which centmin.sh menu option 22 setup wordpress caching does.
    I don't use that plugin so can't really same how far you need to open permissions. You may need 777 even, I should do a test on a test dummy wordpress site setup via centmin.sh menu option 22 so you can mess with test wp site and figure it all out first before messing with live wordpress site. Or just use wordpress native cron ;) :)
     
  13. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    12:41 AM
    1.17.8
    10.3
    Thank you for your concern and I have verified my wordpress cronjobs are working great. There was no issue with server cronjobs as that plugin was messing with only wordpress but now all sorted out. Just need your word if that cronjob rule is fine and will not mess up with stack cause till now everything looks so far so good.
    For the all in one wp migration plugin... I am testing that too on a testing site. Obviously I am not risking my production site without making sure I can make this work. I really want to use server cronjob for my site so I need to set wp-content permission to 775 but at this moment it is 2775... How to remove that extra 2?
     
  14. eva2000

    eva2000 Administrator Staff Member

    44,684
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,792
    Local Time:
    5:11 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Centmin Mod centmin.sh menu option 22 and any nginx vhost menus like option 2 will set directories with setgid bit denoted by 2 in front as it's set at /home/nginx/domain/yourdomain.com level and inherits down all directories so all directories and files created within the parent directory and down are owned by nginx user. So normal see Difference between "chmod 775" and "chmod 2755"
    Chmod 2775