Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got some php scripts that I need to schedule for every hour.

(a) How do I schedule them from the command line / shell?

(b) What permissions / ownership should I set on them?

Edit 1:

Hi guys - the website is being run by 'apache' user. Which user does the cron script run as? root or apache or something else?

share|improve this question
In response to your edit, your crontab runs as you. If you need it to run as the webserver, do what Rikih said and put the files on the webserver, then replace the crontab command with /usr/bin/curl (or /usr/bin/wget) – DerfK Oct 29 '10 at 21:37
up vote 2 down vote accepted

crontab -e will open the crontab editor for your personal crontab, assuming the admin allows them. Here you'd put a line like

0 * * * * /usr/bin/php /home/matt_tm/php/runme.php

once for each script, with /usr/bin/php being the full path to your commandline php binary, and the full path to the php file you want to run.

That will run the script the 0th minute (:00) of every hour, every day of the month, every month, and every day of the week (you might want to spread them out so one script starts at 0, one starts at the 5th minute and so on). The commands in your personal crontab are run as your account, so all your script needs in this case is for your account to be able to read the script, execute the php binary, and have access to all the files the script needs.

share|improve this answer

(a) you can using php-cli or wget/curl (other utilities) (b) execute permission. if the php script need to create the file, make sure the permission same as the user running.

share|improve this answer

to schedule them, edit the cronfile for the user they should run as. "man crontab" should tell you how to do this.

as to what ownership, it all depends what the scripts are supposed to do. if they modify some resource, then the script has to either have user or group permission to modify the resource (assuming this resource is a local file). often the most sensible way to do this on a unix-like system is through group permissions.

share|improve this answer

As an alternative to DerfK answer you could also start each PHP with the line.


and chmod the file to be executable.

Your crontab line will now look like this:

0 * * * * /path/to/php/script.php
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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