Password Protect public_html
- Log in to cPanel.
- For help accessing your cPanel see Where do I log in to my hosting control panel.
- Click Directory Privacy
- Click public_html
- Select Password protect this directory
- Enter a name, for example, website in the Enter a name for the protected directory field
- Click Save
- Click Go back
Create a user
- Enter a username in the Username field under Create User
- Enter a password in the New Password field
- Click Save
Advanced Tips
Set a 401 Error Document
- Log in to cPanel.
- For help accessing your cPanel see Where do I log in to my hosting control panel.
- Click File Manager
- Open public_html, select .htaccess and click edit
- Find the AuthType Basic code:
AuthType Basic AuthName "Dev Site" AuthUserFile "/home/user/.htpasswds/public_html/passwd" require valid-user
-
Add ErrorDocument 401 “Unauthorized” as below:
AuthType Basic AuthName "Dev Site" AuthUserFile "/home/user/.htpasswds/public_html/passwd" require valid-user ErrorDocument 401 "Unauthorized"
Allow server access to your protected website
- Log in to cPanel.
- For help accessing your cPanel see Where do I log in to my hosting control panel.
- Click File Manager
- Open public_html, select .htaccess and click edit
-
Find the AuthType Basic code:
AuthType Basic AuthName "Dev Site" AuthUserFile "/home/user/.htpasswds/public_html/passwd" require valid-user ErrorDocument 401 "Unauthorized"
-
Add RequireAny Require ip options as below:
AuthType Basic AuthName "Dev Site" AuthUserFile "/home/user/.htpasswds/public_html/passwd" <RequireAny> Require ip 127.0.0.1 Require valid-user </RequireAny> ErrorDocument 401 "Unauthorized"