2

Is it possible to define file type permissions through .htaccess? I have a site that uses .pl and .cgi scripts which require 0755 CHMOD. The shared server setting is apparently geared for WordPress which require 0644 CHMOD as it is php-driven, so I'm guessing that my file permissions on .pl and .cgi occasionally get set to a default of 0644, causing "[an error occurred while processing this directive]."

I've tried adding this in the .htaccess, but get a 500 server error. Any help or suggestions would be appreciated. I do not have access to the httpd.conf file.

    chmod .htpasswd files 640
    chmod .htaccess files 644
    chmod php files 600
    chmod pl files 755
    chmod cgi files 755
    chmod cgi files 755
2

Apache's .htaccess files cannot be used to set unix file permissions.

chmod is a command line tool for unix-like systems that is used to change the unix permissions of files on the filesystem. chmod is not an Apache or .htaccess construct, therefore chmod cannot be invoked through a .htaccess file - it can only be invoked by being executed on the server, through the command line or otherwise.

If you have ssh access to your server, you can use chmod there to set the proper file permissions. If you do not, there is a chance that your remote file browser GUI will let you set file permissions.

1

As Maximillian says, you can't do it in .htaccess, but you can do it as a cron job.

Something like 0 * * * * /bin/chmod 755 /home/someuser/*.pl && /bin/chmod 600 /home/someuser/*.php

  • Clever. If I'm reading it right, this cron job will reset the permissions to the correct ones every hour on the hour, forever. – Maximillian Laumeister Oct 27 '18 at 4:08
  • Yes, it will reset permissions every hour (in this case) and only you can decide if they are "correct", you may need to tweak it to suit. – Steve Oct 27 '18 at 8:18
  • Sounds like this might be the best way to go. Thanks for the input. – Cruz Oct 28 '18 at 3:00
  • @Cruz Don't forget to "accept" the answer that ended up being most useful to you. Thanks! – Maximillian Laumeister Oct 29 '18 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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