Mod_auth_basic is an Apache module that allows the use of Basic Authentication capabilities.
Here’s a simple step-by-step process on how to configure mod_auth_basic:
1. First, you need to ensure that the mod_auth_basic module is installed and enabled on your Apache server. You can do this by running the following command:
\`\`\` sudo a2enmod auth\_basic \`\`\` Then restart the apache2 service with \`\`\` sudo service apache2 restart \`\`\`1. Specify the restricted area with the AuthName directive. This displays a message to the users that pops up in the login box:
\`\`\` AuthName “Restricted Area“ \`\`\`1. Use the AuthType Basic directive to specify basic authentication:
\`\`\` AuthType Basic \`\`\`1. Define the authorization file with the AuthUserFile directive:
\`\`\` AuthUserFile /your/directory/.htpasswd \`\`\`1. Lastly, specify who should have access to the directory with the Require directive:
\`\`\` Require valid-user \`\`\` The “valid-user” keyword specifies that any user in the .htpasswd file can access the directory.1. If you want to add user for specified directory, use htpasswd tool that comes with the Apache distribution:
\`\`\` htpasswd -c /your/directory/.htpasswd username \`\`\`Place the mentioned commands into Apache configuration file which is located as “/etc/httpd/conf/httpd.conf” or Apache virtual host file.
After you have edited the configuration files, don’t forget to restart your Apache server to see the changes:
```
sudo service apache2 restart
```
Please note: Change “/your/directory/.htpasswd” to your actual directory path. The .htpasswd file (You can name it anything you want) holds the usernames and passwords in encoded format.