Dino Geek, try to help you

How to use .htpasswd to secure a folder in Apache?


1. Create a .htpasswd file

First, you need to create a .htpasswd file. This file will store your username(s) and password(s). To create this file, you can use a tool like htpasswd. Here’s the command to use: \`\`\`bash htpasswd -c /path/to/.htpasswd username \`\`\` The `-c` flag tells htpasswd to create a new file. `/path/to/.htpasswd` is the full file path where you want the .htpasswd file to be saved, and `username` is the username you want to create. You’ll be prompted to enter a password.

1. Set up .htaccess

Once the .htpasswd file is created, you’ll need to set up your .htaccess file. This file tells Apache to secure a specific directory. Add the following lines in your .htaccess file: \`\`\`bash AuthType Basic AuthName “Restricted Content“ AuthUserFile /path/to/.htpasswd Require valid-user \`\`\` `AuthType` indicates the type of authentication that is being used. `AuthName` is the message for the login prompt. `AuthUserFile` indicates the path of the .htpasswd file. `Require valid-user` tells Apache that only authenticated users can access this directory.

1. Change .htaccess and .htpasswd permission

For security reason, you have to change the .htaccess and .htpasswd files permissions. It will make files inaccessible from the outer world. \`\`\`bash chmod 644 .htaccess chmod 644 .htpasswd \`\`\`

1. Check Apache Configuration

Apache needs to be correctly configured to read .htaccess file. Check that the Apache configuration file (usually called httpd.conf) has the following lines : \`\`\`bash AccessFileName .htaccess \`\`\` And \`\`\`bash AllowOverride All \`\`\` If not, you should add them and restart Apache.

1. Test

Finally, try to access the secured folder via web browser. It should prompt you for a username and password before allowing access.

Remember that the .htaccess and .htpasswd files are very powerful and sensitive, and a small mistake can cause big problems, so handle with care.


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