2

So I've spent around 2-3 hours now and some times researching, I found several of the same responses online but none seem to work!

I'm trying to execute a PHP script every minute (as a test), but it doesn't work.

This is crontab in /etc/crontab I honestly don't see what's wrong with that script. So I've went to check the logs and I get this;

May 1 19:59:01 namehere crond[1112]: (system) RELOAD (/etc/crontab) May 1 19:59:01 namehere crond[1112]: (CRON) bad username (/etc/crontab)

I am quite confused, any help would be greatly appreciated!

I have LAMP installed and php-cli if that matters.

EDIT:

I finally made it execute! Thanks to the poster below! However, I now have another problem, I get emailed an error enter image description here My script includes other scripts, when I was on cPanel (shared hosting), it worked perfectly, but now it doesn't, what could be the problem?

  • This is another programming/PHP related problem that you have updated, I strongly suggest posting is as a separate question on stackoverflow.com as it will also require more details on how your program is structured. – phoops May 1 '14 at 21:10
3

You seem to have some version of cron which expects a user-name parameter before the command. It is even in the header, just a bit concealed:

*  *  *  *  * <user-name> <command to be executed>

Try this (replace root with whatever user php/apache runs at):

* * * * * root /usr/bin/php /var/www/html/directory/file.php

Also, note that some distributions have separate php.ini configurations depending if it is used via command line (cli) or as apache module etc. So if you run into more problems, make sure your php.ini files match (check /etc/php).

Update

For absolute paths to work, have your includes like this:

include __FILE__ . '../inc/databases.php';

Note the added __FILE__ which returns absolue path to current running script. You will have to update all include and require.

  • Thanks for your reply @edvinas.me - You've got it to work, great! but now I have another problem: link The script also includes files from another script, when i was on cPanel (shared hosting) it worked perfectly, but now it doesn't? Do you think you know what could be wrong? Thanks. – helpMe664 May 1 '14 at 20:49
  • The relative paths do not work, you have to use absolute paths or something like stackoverflow.com/questions/10844641/… Feel free to post another question on StackExchange. Also don't forget to accept answers that helped you! – phoops May 1 '14 at 21:09
  • actually I think there is an easier way I have updated my answer. – phoops May 1 '14 at 21:12
  • Hey, thanks for your help! I'll have a test shortly. But I'm sure there is a way where I won't need to provide an absolute path, seeing if cPanel and zPanel could successfully do it right? @edvinas.me – helpMe664 May 1 '14 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.