How to Configure a WebDAV Folder on AlmaLinux 9?

How to Configure a WebDAV Folder on AlmaLinux 9?

November 2, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu
Web Distributed Authoring and Versioning (WebDAV) is a protocol that enables web users to manage files on a server just as if they were stored locally on their machine. WebDAV is useful in various scenarios, from collaborative file management to simple web-based file storage. In this tutorial, we’ll walk through configuring a WebDAV folder on AlmaLinux 9, one of the latest and most popular RHEL-based distributions. ### 1. Introduction to WebDAV WebDAV is a protocol that enhances the HTTP standard to allow users to edit and manage files on a remote server. This capability is often used for content management and collaborative projects. It integrates easily with various operating systems, making it a flexible choice for network-based file storage and management.
### 2. Prerequisites Before starting, ensure you have the following:
  • AlmaLinux 9 : Installed and configured with root or sudo privileges.
  • Apache HTTP Server : As WebDAV uses HTTP, Apache is required for this setup.
  • Open Ports : Port 80 (HTTP) or 443 (HTTPS) should be open.
  • Basic Networking Knowledge : Familiarity with basic Linux commands and networking is beneficial.

### 3. Install Apache and WebDAV Modules To set up WebDAV, you first need to install Apache and enable WebDAV-related modules. Follow these steps: #### Step 1: Update System Packages It’s always good practice to update your system packages before making installations.
sudo dnf update -y
#### Step 2: Install Apache Web Server To install Apache, run:
sudo dnf install httpd -y
#### Step 3: Enable and Start Apache Service Once installed, enable and start the Apache service.
sudo systemctl enable httpd
sudo systemctl start httpd
#### Step 4: Install WebDAV Modules WebDAV functionality in Apache is supported through two main modules, dav and dav_fs. These modules are usually included by default in Apache installations. To install them, run:
sudo dnf install mod_dav mod_dav_fs -y
You can verify that the modules are loaded by checking Apache’s configuration file, typically located in /etc/httpd/conf/httpd.conf.
### 4. Configure WebDAV Directory Next, we need to configure the directory on the server where files will be stored and accessed. #### Step 1: Create the WebDAV Directory Create a new directory to serve as the WebDAV folder.
sudo mkdir -p /var/www/html/webdav
#### Step 2: Set Permissions Set appropriate permissions for the directory. You can choose who can read and write by adjusting permissions or creating a dedicated user group.
sudo chown -R apache:apache /var/www/html/webdav
sudo chmod -R 755 /var/www/html/webdav
#### Step 3: Configure the WebDAV Directory in Apache Add configuration to allow WebDAV access to the directory.

Open Apache’s configuration file or create a new configuration file specifically for WebDAV:

sudo nano /etc/httpd/conf.d/webdav.conf

Add the following configuration:

<Directory /var/www/html/webdav>
    Dav On
    Options Indexes FollowSymLinks
    AllowOverride None
    Require valid-user
</Directory>

Alias /webdav /var/www/html/webdav

This configuration enables WebDAV on the /webdav directory and requires authentication.


### 5. Setting Up Authentication To restrict access, configure basic authentication for WebDAV. #### Step 1: Install httpd-tools Install the httpd-tools package, which includes the htpasswd utility for creating password files.
sudo dnf install httpd-tools -y
#### Step 2: Create a Password File Create a password file for WebDAV authentication.
sudo htpasswd -c /etc/httpd/.htpasswd webdav_user
Enter a password when prompted. To add more users, omit the -c flag:
sudo htpasswd /etc/httpd/.htpasswd another_user
#### Step 3: Update Apache Configuration for Authentication In your webdav.conf file, add the following lines within the <Directory> block:
AuthType Basic
AuthName "Restricted WebDAV Folder"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user
Save and close the file. #### Step 4: Restart Apache To apply the changes, restart Apache:
sudo systemctl restart httpd

### 6. Configuring Firewall Rules If your firewall is active, ensure that Apache traffic is allowed.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

### 7. Testing WebDAV Configuration To test if WebDAV is functioning properly, open a web browser and navigate to http://your-server-ip/webdav. You should be prompted for a username and password. Enter the credentials set up in the .htpasswd file. If access is successful, your WebDAV setup is working!
### 8. Mounting the WebDAV Folder Once WebDAV is set up, you can mount the folder on various operating systems. Here’s how to do it on a few popular systems. #### On Linux You can mount a WebDAV share in Linux using the davfs2 package.

Install davfs2:

sudo dnf install davfs2 -y

Mount the WebDAV folder:

sudo mount -t davfs http://your-server-ip/webdav /mnt/webdav

On Windows

  • Open File Explorer.
  • Right-click on “This PC” and select “Map network drive.”
  • In the Folder field, type: http://your-server-ip/webdav.
  • Enter your WebDAV username and password when prompted.

On macOS

  • In Finder, press Cmd + K.
  • Enter the WebDAV URL: http://your-server-ip/webdav.
  • Click “Connect” and enter your WebDAV credentials.

### 9. Troubleshooting Tips If you encounter issues, try these troubleshooting tips:
  • Check Apache Error Logs : Use sudo tail -f /var/log/httpd/error_log to view Apache logs for possible configuration errors.
  • Verify File Permissions : Ensure the apache user has permissions to the WebDAV directory.
  • Ensure Correct URL : Make sure the URL path is correct, especially when connecting from different operating systems.
  • Firewall Settings : Confirm that firewall rules are applied correctly.

### 10. Conclusion Configuring a WebDAV folder on AlmaLinux 9 is straightforward with Apache and a few additional configurations. WebDAV enables remote file management, enhancing collaboration and file accessibility. By following this guide, you should now have a secure and functional WebDAV setup on your AlmaLinux server. WebDAV offers a practical solution for shared file management, and with proper configuration, it can be a powerful tool for businesses and individual users alike.
Last updated on