Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 have a website which I run a PHP script for updating its Database. What is considered to be an acceptable location on the server to store such scripts? Obviously only the root (running a cronjob to start the script) should have access to it.



share|improve this question
up vote 1 down vote accepted

If you are worried about access to this script you can add a random string to the command line argument of the cron job string e.g.

php /path/to/script.php random_string

Then in your script.php you check argv0 to see if that string is exists and is correct before running the rest of your code.

Another way is to put the cron script in a folder and restrict its access using a .htaccess file. Here is an answer on how to do this: http://serverfault.com/questions/92192/apache-htaccess-file-to-restrict-access-to-all-files-unless-local-ip

share|improve this answer
Why not just put the script outside of your web root directory? – Lèse majesté Nov 18 '10 at 11:45
Yes that is a very valid point! – mar10 Nov 18 '10 at 12:12
Actually I was aiming to that point. I was wondering if there is a directory outside of the web root directory, that it is common to put scripts within. – Joel Nov 18 '10 at 12:32
@Joel: AFAIK, there is no common directory that such scripts are put in. I normally group these types of scripts with the application that it belongs to, so it just depends on their directory structure. As long as it's outside of your web root and inside your home directory (for shared hosting), then it's equally safe wherever you put it. – Lèse majesté Nov 18 '10 at 17:09

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.