b2evolution b2evolution

  • Sign in
  • Sign up
  • About
  • Downloads
  • Hosting
  • Docs
  • Support
  • Sign in
  • Sign up
  • Manuals Home
  • Latest Updates
 
  1. b2evolution CMS User Manual
  2. Installation / Upgrade
  3. Advanced Setup
  4. Setting up the Scheduler
  5. Linux Cron Job Setup

Linux Cron Job Setup

Warning: The following assumes you have your own Linux server with root access. Blindly following this procedure may lead to breaking your Linux setup. DO NOT do this if you don’t understand it. Use this page only as a guideline.

Running the cron_exec.php script

You will want to execute your cron/cron_exec.php script on a regular basis.

First, you’ll need to know exactly where this script resides on your system. You could try using this command: locate cron_exec.php

Note: if you have just uploaded the script it will not be found. In this case type updatedb to refresh your locate database.

Once you know where the script file is, you need to use the PHP interpreter in order to run it.

Note: PHP comes in different flavors: Apache module, CGI module, CLI, etc. The preferred version to use here is the CLI (Command Line Interface).

You could try using this command: /usr/bin/php -v

If you’re set up correctly you should get something like:

  PHP 4.3.10-16 (cli) (built: Aug 24 2005 20:25:01)
  Copyright (c) 1997-2004 The PHP Group
  Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

Notice the (cli) after the version number?

If you get an error, you may not have the PHP CLI package installed. Under DEBIAN, the package you want to install is php-cli

If you get a lot of HTML, then you’re running PHP but not the CLI version. This is not optimal but may work anyway.

Now try running the cron_exec from the command line: /usr/bin/php /your/specific/path/cron/cron_exec.php

You may get an error about MySQL needing to be enabled. This must be done in php.ini (again, location may vary, use locate php.ini). Un-comment the following line then try running the command again:

extension=mysql.so

When the script runs, it either outputs a lot of info about the scheduled job it executes, or when there is no job to execute, it would simply output something like:

There is no task to execute yet.

Automate execution of cron_exec.php script

Now that you can run the script from the command line, let’s automate it…

Edit the file /etc/crontab and add the following line:

*  *    * * *   root  /usr/bin/php /your/own/path/cron/cron_exec.php >/dev/null 2>/dev/null

Note: root is the user under which the script will be run, you may want to change that.

Also >/dev/null 2>/dev/null discards all messages and error messages, you may want to redirect those to a file for debugging purposes.

Automating cron jobs for multiple instances of b2evolution

This is for advanced users only.

If you are running multiple instances of b2evolution on the same server you may wish your system to automatically run new cron_exec scripts as you install them.

One solution would be to place this into /usr/local/bin/evo-cron:

  #!/bin/bash

  # Get list of crons we can run:
  CronList=`ls /home/*/www/cron/cron_exec.php`

  # Loop though all sites
  for Cron in $CronList
  do
    echo $Cron
    /usr/bin/php $Cron
  done

And call it like this in /etc/crontab:

*  *    * * *   www-data  /usr/local/bin/evo-cron
Created by fatimahnasra • Last edit by winskie on 2019-08-15 04:39 • •

1 comment

Comment from: fede

fede

If you get a mysql error when running the cron job, like "MySQL error! Error establishing a database connection!", try using ‘127.0.0.1′, instead of ‘localhost’ as host name in _basic.config.php, because PHP treats these two values differently:

  • ‘localhost’ means that PHP will try using a named pipe to connect to the database. This is usually faster but is prone to breakage due to permissions (what happens when the CLI and web versions of PHP run under different system users)
  • ‘127.0.0.1′ means that PHP will try using TCP/IP to connect to the database. Unless your host has disabled that MySQL feature, this is the most resilient connection method.
2014-07-15 @ 19:27

On this page

  • Running the cron_exec.php script
  • Automate execution of cron_exec.php script
  • Automating cron jobs for multiple instances of b2evolution

Search the Manual

Content Hierarchy

  • b2evolution CMS User Manual
  • User's Guide
  • Installation / Upgrade
    • New Installation
    • Upgrade
    • Configuration files
    • Advanced Setup
      • Test features
      • Intranet installation
      • Intranet setup
      • After Installation / Upgrade
      • Setting up the Scheduler
        • Linux Cron Job Setup
        • cPanel Cron Job Setup
        • Windows Scheduled Task Setup
      • Multi-Domain Setup
      • Multiple instances
      • File Permissions
      • How to change the location of admin.php
      • Google API key
      • GitHub API key
    • Migrating from Another System
    • Moving your b2evolution Site
    • FAQ & Troubleshooting (Installation / Upgrade)
    • Assumed User Skills
  • Front-office Reference
  • Back-office Reference
  • Developer Reference
  • Operations Reference
  • Advanced Topics
  • Glossary
  • Archives
b2evo

This online manual is powered by b2evolution CMS – A complete engine for your website.

About b2evolution

  • What is it?
  • Features
  • Getting Started
  • Screenshots
  • Online demo
  • Testimonials
  • Design philosophy
  • Free & open source
  • Terms of service

Downloads

  • Latest releases
  • Skins
  • Plugins
  • Language packs

About us

  • About us
  • Contact

Webhosting Guide

  • Web hosting blog
  • Best web hosting
  • Cheap web hosting
  • Green web hosting
  • Hosting with SSH
  • VPS hosting
  • Dedicated servers
  • Reseller hosting
  • Int'l: UK / France

Docs & Support

  • Online manual
  • Forums
  • Hire a pro !

Other

  • Adsense
  • Press room
  • Privacy policy

Stay in touch

  • GitHub
  • Twitter
  • Facebook
  • LinkedIn
  • News blog
  • RSS feed
  • Atom feed

Founded & Maintained by François Planque