Every so often I need a quick way to password protect folder contents on a shared Apache/cPanel host—staging dumps, private zips, a client preview directory—without installing a full membership plugin.
Apache Basic Auth with a local .htaccess plus .htpasswd is still the fastest approach I use for that. Two small files in the folder, update the path, reload the browser, done.

When I Password Protect Folder Access This Way
This is for directory-level protection on Apache. It is not WordPress login, and it is not a replacement for HTTPS. I use it as a temporary gate on a folder, then remove the files when the work is finished.
On the same servers I often pair folder locks with other Apache notes like redirecting HTTP to HTTPS and exact URL redirects when changing a domain. For local Mac Apache permission quirks, I keep macOS localhost permissions for Apache nearby.

Step 1: Create .htaccess to Password Protect Folder
Inside the folder you want to lock, create a file named .htaccess with this content:
AuthName "Password Protected!"
AuthType Basic
AuthUserFile /home/cpanel_user_name/public_html/folder_name/.htpasswd
require valid-userChange cpanel_user_name and folder_name so AuthUserFile points to the real absolute path of your .htpasswd file. Relative paths here are unreliable on many hosts.

Step 2: Create the .htpasswd File
In the same folder, create .htpasswd. A simple username/password line looks like this for a quick test:
asiq:12345That plain example is fine for remembering the format on a throwaway folder. For anything real, generate a hashed password with the htpasswd utility (or your host’s password-protect UI) instead of storing a readable password.
htpasswd -c /home/cpanel_user_name/public_html/folder_name/.htpasswd asiqThe -c flag creates the file. Omit -c when adding more users later so you do not wipe existing entries.
Quick Checks After You Password Protect Folder Files
- Visit the folder URL in a private/incognito window—you should get a browser login prompt
- If Apache ignores
.htaccess, ask the host whetherAllowOverride AuthConfig(orAll) is enabled for that directory - Confirm the
AuthUserFilepath is absolute and readable by the web server user - Keep
.htpasswdoutside the web root when you can; if it must sit inpublic_html, make sure directory listing is off
Once Basic Auth works, I still prefer serving the site over HTTPS so the credentials are not sent in clear text on the wire.
FAQ: Password Protect Folder with .htaccess
Does this work on Nginx?
No. This exact method is Apache .htaccess Basic Auth. Nginx uses a different auth_basic configuration in the server block.
Can I password protect folder paths inside WordPress?
Yes for physical directories under the site root (uploads subfolders, staging dirs). It will not replace WordPress roles for posts and pages.
Why do I get a 500 error after adding .htaccess?
Usually a bad AuthUserFile path, missing .htpasswd, or the host disallowing Auth overrides. Check the Apache error log first.
Is Basic Auth enough for sensitive data?
It is a convenient gate, not high security. Use strong hashed passwords, HTTPS, and avoid leaving long-lived private archives in public_html.
Conclusion
Need to password protect folder files on Apache quickly? Drop in .htaccess with Basic Auth, point AuthUserFile at a real .htpasswd, and test in a private window. Hash passwords for real use, keep HTTPS on, and delete the lock when the folder no longer needs it.

