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

How to close access for a few bash scripts that are used by my PHP-Apache-based website?

I have an index.php file in my document root /var/www/. index.php is supposed to call some bash scripts which are currently in the /var/www/scripts/ directory. However I don't like the fact that these scripts can be downloaded from the Internet by requesting

How to close access to the scripts, allowing them to be called by index.php?

share|improve this question
up vote 1 down vote accepted

You should be able to use the FilesMatch directive:

with an Order and Allow and Deny directives.


share|improve this answer
A rather dangerous idea (because the matching is easy to get wrong). Rather use Kamil's proposal. – sleske Oct 27 '09 at 14:56

You should place the scripts outside of the site's directory so they cannot be download no matter what happens with the server configuration or permissions. You can still execute them from your PHP code so long as the apache process has execute permission on them.

share|improve this answer
+1 Definitely the right answer. – David Pashley Oct 25 '09 at 19:34

If you exec these scripts from within the PHP script, no one should have an idea of their existance. Anyway you can put a .htaccess file with a Deny ALL directive to restrict everybody's access from Apache to that directory. It is another question why you would need a scripts directory under your DocumentRoot, but I assume there are some hosting providers that don't give you another directory...

share|improve this answer

Might not hurt to obfuscate the scripts with this shell script 'compiler' called shc. (not really a compiler).

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.