Dino Geek, try to help you

How to configure password authentication for a directory on Apache?


Password protection for a specific directory on the Apache web server can be configured by using a `.htaccess` file. Here is how you can do it:

1. Create a password file: The first step in the process is to create a text file, which stores the usernames and their corresponding passwords.

This text file should ideally not be stored in a public accessible directory. The Apache `htpasswd` tool is used for this purpose. For example, if you want to create a user called ‘admin’, you can use this command: \`\`\`bash htpasswd -c /etc/apache2/.htpasswd admin \`\`\` You’ll be prompted to supply and confirm your password for the user.

1. Setting up `.htaccess` file: Next you’ll need to set the configuration in a `.htaccess` file in your directory. Here’s an example:

\`\`\`bash AuthType Basic AuthName “Restricted Content“ AuthUserFile /etc/apache2/.htpasswd Require valid-user \`\`\` In this example, `AuthType Basic` refers to the type of authentication being used, `AuthName` provides a message for the authentication dialogue, `AuthUserFile` specifies the location of the password file, and `Require valid-user` allows any valid user to access the directory.

1. Configure Apache to Allow .htaccess Overrides: Go to Apache configuration file `apache2.conf` or `httpd.conf` in `/etc/apache2/`:

\`\`\`bash nano /etc/apache2/apache2.conf \`\`\` Then, look for a section having your directory information – something like this: \`\`\`bash . . . \`\`\` Add `AllowOverride All` to this `` block: \`\`\`bash . . . AllowOverride All \`\`\` After doing this, save and close the file.

1. Restart Apache: Once all the configurations are done, remember to restart the Apache2 service so that the changes can take effect.

\`\`\`bash systemctl restart apache2 \`\`\`

After these steps, when you try to access the given directory in a browser, it should ask for a username and password.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use