How do I lock files in my public_html directory?

The best way of doing this is to use a combination of a .htaccess file and a .htpasswd in the directory you would like to lock.

An easy way to generate these 2 files can be found here.

An example .htaccess file:

AuthName “Restricted Stuff”
AuthType Basic
AuthUserFile /home/YOUR_USERNAME/Path to .htpasswd file

require valid-user
An example .htpasswd file:



Note that you shouldn’t have the .htpasswd file in a web accessible folder.

Once you have made both files you need to change the permissions using:

chmod 655 .htaccess .htpasswd

Posted in: Websites and pages