Password protecting a directory on cPanel

Password protecting a directory restricts access to certain parts of your website by requiring visitors to enter a username and a password. This password process is also referred to as a type of “authentication” process.

cPanel Password Protect Directory icon.

(cPanel >> Security >> Password Protect Directories)

You can manually create password protect by using the following steps.

Create .htpasswd file for users and passwords:

htpasswd -c /path/to/file/.htpasswd username

This command will prompt you for the password.

Edit .htaccess:

AuthName “Members Only”
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
require valid-user
deny from all

You can protect more than one file by using wildcard names. On the FilesMatch line, follow one of these examples:
<FilesMatch “*.php”>
<FilesMatch “file.*”>
<FilesMatch “*.*”>


<FilesMatch “*.php”>
AuthName “Member Only”
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

cPanel & WHM Version 74 Now in STABLE

cPanel has released cPanel & WHM Version 74 to the STABLE tier. It includes updates for some...

Installing cpanel on google cloud

Create a new CentOS 7 instance on your google cloud engine. From the cPanel & WHM System...

Install Free SSL Let’s Encrypt plugin in cPanel

Let’s Encrypt is a trusted, open source certificate authority that offers free SSL certificates...

Replace MySQL with Percona in cPanel Server

Percona Server is an enhanced drop-in replacement for MySQL. If you are a web hosting service...

Install nginx as a reverse proxy cPanel plugin

Install Nginx on your cPanel/WHM server using the Engintron cPanel Plugin as a reverse proxy. It...

Powered by WHMCompleteSolution