• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Apache for Newbie: Set up Apache with mod_auth_basic

December 17, 2023

Apache for Newbie: Set up Apache with mod_auth_basic

Apache is one of the most popular web servers in the world, known for its flexibility, reliability, and security. If you are new to Apache and want to learn how to set it up with mod_auth_basic, this article is for you. Mod_auth_basic is an Apache module that provides basic authentication for web pages, allowing you to restrict access to certain areas of your website.

Step 1: Install Apache

The first step is to install Apache on your server. If you are using a Hong Kong VPS hosting service like Server.HK, you can easily install Apache using the control panel provided by your hosting provider. Alternatively, you can install Apache manually by following the instructions on the Apache website.

Once Apache is installed, you can start and enable it by running the following commands:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 2: Enable mod_auth_basic

After installing Apache, you need to enable the mod_auth_basic module. This module is usually included with the default Apache installation, but it may not be enabled by default. To enable it, run the following command:

sudo a2enmod auth_basic

This command will create a symbolic link in the Apache configuration directory, enabling the mod_auth_basic module.

Step 3: Configure Authentication

Once mod_auth_basic is enabled, you can start configuring authentication for your website. Open the Apache configuration file using a text editor:

sudo nano /etc/apache2/apache2.conf

Inside the configuration file, you can add the following code to set up basic authentication:

<Directory /var/www/html/private>
    AuthType Basic
    AuthName "Restricted Area"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
</Directory>

In this example, we are setting up basic authentication for the “/var/www/html/private” directory. You can change the directory path to match the location you want to protect.

The “AuthUserFile” directive specifies the location of the password file. You need to create this file and add user credentials using the htpasswd utility. Run the following command to create the password file:

sudo htpasswd -c /etc/apache2/.htpasswd username

Replace “username” with the desired username for authentication. You will be prompted to enter and confirm the password for the user.

Step 4: Restart Apache

After configuring authentication, you need to restart Apache for the changes to take effect. Run the following command to restart Apache:

sudo systemctl restart apache2

Summary

Setting up Apache with mod_auth_basic allows you to add basic authentication to your website, restricting access to certain areas. By following the steps outlined in this article, you can easily set up Apache with mod_auth_basic on your Hong Kong VPS hosting server. Remember to install Apache, enable mod_auth_basic, configure authentication, and restart Apache to apply the changes.

By incorporating basic authentication, you can enhance the security of your website and protect sensitive information. Whether you are hosting a personal blog or an e-commerce site, Apache with mod_auth_basic is a valuable tool for controlling access to your web pages.

For reliable and secure Hong Kong VPS hosting services, consider Server.HK. With their high-performance servers and excellent customer support, Server.HK is the perfect choice for hosting your website. Visit https://server.hk to learn more about their hosting solutions.

Recent Posts

  • How to Migrate from CentOS 8 to AlmaLinux or Rocky Linux Safely
  • CentOS Server Performance Tuning: Optimization Techniques for 2026
  • How to Configure SELinux in CentOS Without Breaking Your System (CentOS Stream 9/10 – 2026)
  • Managing Users and Permissions in CentOS Stream: Best Practices (CentOS Stream 9/10 – 2026)
  • How to Set Up Nginx on CentOS Stream for High-Performance Web Hosting

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot