Follow the below steps to replicate the correct configs:
sudo htpasswd -c /etc/apache2/.htpasswd <user-name>
Enter Password and confirm
sudo nano /etc/apache2/sites-enabled/000-default.conf
Add the following text:
<Directory "/var/www/html">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
This should be inside VirtualHost tag
sudo service apache2 restart
sudo nano /etc/apache2/apache2.conf
Change the highlighted entry to all in the doc
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
sudo nano /var/www/html/.htaccess
enter the following content:
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
sudo service apache2 restart
For more information, check out this apache spark.