Ubuntu 20.04
Sponsored Link

Apache2 : Basic Authentication2020/05/07

Set Basic Authentication to limit access on specific web pages.
Username and password are sent with plain text on Basic Authentication, so Use secure connection with SSL/TLS setting, refer to here.
[2] Configure httpd.
For example, set Basic Authentication to the directory [/var/www/html/auth-basic].
apt -y install apache2-utils
vi /etc/apache2/sites-available/auth-basic.conf
# create new

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

# add a user : create a new file with [-c]

htpasswd -c /etc/apache2/.htpasswd ubuntu

New password:    
# set password

Re-type new password:
Adding password for user ubuntu
mkdir /var/www/html/auth-basic

a2ensite auth-basic

Enabling site auth-basic.
To activate the new configuration, you need to run:
  service apache2 reload

systemctl restart apache2
# create a test page

vi /var/www/html/auth-basic/index.html
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for Basic Authentication
[3] Access to the test page from any client computer with web browser. Then authentication is required as settings, answer with a user added in [1].
[4] It's OK if authentication is successfully passed and test page is displayed normally.
Matched Content