I'm presently on a dedicated server running FreeBSD, and Apache using mod_php. CGI isn't presently an option due to long-running scripts on one of the domains.

I'm presently using a simple script to unsecure/secure an installation; but the secure script does not appear to always execute the chmods for e.g. the cache directory.

find ./public_html -type f ! -user apache -exec chmod 644 {} \;
find ./public_html -type d ! -user apache -exec chmod 755 {} \;
chmod -R 777 public_html/cache/
chmod -R 777 public_html/administrator/cache/
chmod -R 777 public_html/logs/
chmod -R 777 public_html/tmp/
chmod -R 777 public_html/components/com_sh404_sef/cache/
chmod -R 777 public_html/downloads/    
chmod -R 777 public_html/content/

In the above, quite often I find the cache directories unwritable after running the script. If I execute all commands one after another on the command line it works as expected It'd be great if you might have an idea what I should be looking at instead?

Thanks for any suggestion.

2 Answers 2


There 2 options for you either use the http.conf or the .htaccess file. Since you run a dedicated host your best options is the http.conf file that only users with a dedicated host can access and modify.

I have no experience with that file so I can not offer a solution. I am using the .access file since I am on a shares host.

  • Sorry, but I think you may have to re-read the question, because I can't figure how your answer relates to it. My question is why my shell script does not do the same thing as running the commands individually. May 4, 2017 at 8:56
  • If you want to use a cache that will be through either of those files. And the cache will not be set if some one/robot is using it. See it as deleting a file while it is running on your pc, it won't let you. Put your site offline and see if that works
    – Paul Raver
    May 5, 2017 at 14:35
  • Thanks for taking the time to comment, but again this hasn't got anything to do with cache or anything. It's simply the execution of the shell script being different to running the commands individually in tcsh. May 6, 2017 at 17:20
  • Alas then I can not help you, my experience is with shared hosts and it sounded familiar in any case good luck.
    – Paul Raver
    May 8, 2017 at 4:00

I'm still not sure why it doesn't work this way, but I've now found that find ...directory also includes the directory itself. So I've now changed the chmod commands to

find public_html/cache/ public_html/administrator/cache/ public_html/logs/  -type f ! -user apache -exec chmod 666{} \;
find public_html/cache/ public_html/administrator/cache/ public_html/logs/ -type d ! -user apache -exec chmod 777{} \;

That works for me. I recon that during shell execution in a row, it errors out once it encounters a file/directory where the script does not have rights to chmod.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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