Security is a fist priority, and if you maintain data security, you have a great responsibility. If you are an administrator and want to provide access to a specific website to the user you need, who has only login information, this article will help you configure basic Apache authentication using a virtual host.

Create a virtual host for out test domain

# nano /etc/httpd/conf.d/

<VirtualHost *:80>
   DocumentRoot /var/www/html
   DirectoryIndex index.php

Create a test webpage

# nano /var/www/html/index.php

<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Test Page

Create an authentication config

# nano /etc/httpd/conf.d/auth.conf

<Directory /var/www/html/>
AuthType Basic
AuthName "Basic Authentication"
AuthUserFile /etc/httpd/conf/.htpasswd
require valid-user

Create a password for user

# htpasswd -c /etc/httpd/conf/.htpasswd unihost

Verify configuration, open your website

Enter the password

You’ve now set up basic authentication for your site