Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 http://mysite.com/scripts/script1.sh.

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

share|improve this question

4 Answers 4

up vote 1 down vote accepted

You should be able to use the FilesMatch directive:

http://httpd.apache.org/docs/2.2/mod/core.html#filesmatch

with an Order and Allow and Deny directives.

Cheers

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

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

share|improve this answer

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

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

Your Answer

 
discard

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.