- b2evolution CMS User Manual
- Back-office Reference
- System
- Scheduler
- Linux Cron Job Setup
Linux Cron Job Setup
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
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.
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
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
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: