Especially when working on foreign systems/servers it might be hard to determine where the .htpasswd file would go if you need an access restricted area while developing the website without taking the server offline.

Here is a short PHP script on how to find it:

*Info: Save this as findHtPasswd.php and run it on the host like https://this.host.com/findHtPasswd.php, copy the code and create a simple .htaccess file pointing to the correct location.

You do still need an according .htpasswd.

There are many good generators for this, basically you concatenate the username with a ‘:’ and the according password as an md5 string likes so: test:$apr1$6wCbqa9L$GgxjeCAvcK29j5rAMnBBc1*

<?php

$dir = dirname(__FILE__);
echo '<p>AuthType Basic</p>';
echo '<p>AuthName "Protected Area"</p>';
echo '<p>AuthUserFile ' . $dir  . '/.htpasswd</p>';
echo '<p>Require valid-user</p>';