If you want to get a WebDAV share running quickly on Ubuntu, Apache2 can handle it with just a few configuration steps. The basic process is to install Apache, enable the DAV-related modules, create a password file for authentication, and then add a dedicated virtual host for WebDAV access.

Install Apache2

Start by installing Apache2:

sudo apt-get install apache2

Enable the WebDAV modules

Turn on the required modules:

sudo a2enmod dav_fs
sudo a2enmod dav
sudo a2enmod dav_lock

Then create the necessary module links:

sudo ln -s /etc/apache2/mods-available/dav.load /etc/apache2/mods-enabled/dav.load sudo ln -s /etc/apache2/mods-available/dav_fs.load /etc/apache2/mods-enabled/dav_fs.load sudo ln -s /etc/apache2/mods-available/dav_lock.load /etc/apache2/mods-enabled/dav_lock.load sudo ln -s /etc/apache2/mods-available/dav_fs.conf /etc/apache2/mods-enabled/dav_fs.conf

Add a listening port

Edit /etc/apache2/ports.conf and add another listening port:

Listen 8080 #也可以改成其他端口

Port 8080 is only an example here, so you can change it if needed.

Create a WebDAV user

Create a user account for WebDAV access. Replace xxx with the username you want to use. The password file path and filename can also be changed if you prefer. After running the command, you will be prompted to enter and confirm a password.

sudo htpasswd -c /etc/apache2/webdav.password xxx

After that, set the password file permissions:

sudo chown root:www-data /etc/apache2/webdav.password
sudo chmod 640 /etc/apache2/webdav.password

Configure the virtual host

Edit /etc/apache2/sites-available/000-default.conf, or replace its contents directly with the following configuration:

# 新添加一个IP端口8080的虚拟主机,该主机给webDav使用
<VirtualHost *:8080>
    #物理路径(根据需要改成自己的位置,例如物理路径为/var/www/share)
    DocumentRoot /var/www/share

    #针对物理路径的配置
    <Directory /var/www/share>
        #允许目录浏览和多视图
        Options Indexes MultiViews

        #禁止使用 .htaccess 文件覆盖配置
        AllowOverride None

        #控制访问权限,允许所有客户端访问此目录
        Order allow,deny
        allow from all
    </Directory>

    #要暴露的网络地址和对应的物理路径
    Alias /webdav /var/www/share

    #针对 /webdav 网络地址的配置,本机地址:http://127.0.0.1:8080/webdav
    <Location /webdav>
        #启用 WebDAV 功能
        DAV On
        #启用基本身份验证,设置认证类型为Basic或者Digest
        AuthType Basic
        #设置认证对话框的提示信息,自由填写
        AuthName "webdav"
        #指定用户名和密码的文件
        AuthUserFile /etc/apache2/webdav.password
        #仅指定用户名叫"admin"的用户可访问,去掉 #号生效
        #Require user admin
        #允许密码文件中的所有用户访问
        Require valid-user
    </Location>

</VirtualHost>

This setup exposes /var/www/share through the /webdav URL path. With the configuration above, the local access address would be:

http://127.0.0.1:8080/webdav

If your shared directory is different, update both DocumentRoot and the related path settings accordingly.

Set directory ownership

Make sure the shared directory is owned by the Apache runtime user:

sudo chown www-data:www-data /var/www/share

Restart Apache2

Finally, restart Apache so the configuration takes effect:

sudo /etc/init.d/apache2 restart

Once Apache comes back up, the WebDAV service should be available on the port you configured, using the username and password stored in the password file.