How to create Apache htpasswd file in Linux OS?

by | 12 Feb 2017 | CentOS, Debian, Fedora, Linux, OS, RHEL, Server, Technology | 0 comments

What is htpasswd?

At times during web development, we will need to prevent the whole world from being able to access a particular website. That’s when Apache htpasswd comes into the picture. htpasswd is usually used together with htaccess.

Tutorial

This tutorial will teach you how to create a htpasswd file using command line.

Creating a htpasswd for the first time

htpasswd -c /<PATH_TO_YOUR_HTPASSWD_FILE>/.htpasswd <USERNAME>

Example

htpasswd -c /var/www/yourdomain.com/.htpasswd themerv

Appending new user to existing htpasswd file

htpasswd /<PATH_TO_YOUR_HTPASSWD_FILE>/.htpasswd <USERNAME>

Example

htpasswd -c /var/www/yourdomain.com/.htpasswd themerv

Using htpasswd in htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/yourdomain.com/.htpasswd
require valid-user

 

That’s it you are done!

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Posts

APCCentOSFedoraLinuxOSPHPProgrammingServerTechnology
Install APC (Alternative PHP Cache) in CentOS 5/6/7 and Fedora 20/21

Install APC (Alternative PHP Cache) in CentOS 5/6/7 and Fedora 20/21

APC (Alternative PHP Cache) is a free and open source tool to cache PHP codes. 1. Install Dependency Packages for APC yum install php-pear php-devel httpd-devel pcre-devel gcc make -y 2. Install APC using PECL (PHP Extension Community Library) pecl install apc...