AlpineLinux 3.8: Install webdav for WebDAV server

This article will describe installing webdav.

1 Install webdav

  • This article uses default SSL/TLS certicication file for https. Please change your SSL/TLS certification file.
  • For closing http, use firewall with awall.
  • Use https or davs for SSL.
  • WEBDAV_USERNAME is username and WEBDAV_PASSWORD is password for digest authentication.
#!/bin/sh -e


[ -z "${WEBDAV_USERNAME}" ] && \
  WEBDAV_USERNAME=admin
[ -z "${WEBDAV_PASSWORD}" ] && \
  WEBDAV_PASSWORD=webdav

# Install webdav.
sudo apk add apache2-webdav apache2-utils apache2-ssl
sudo rc-update add apache2
sudo rc-service apache2 start

# Create directory for webdav.
sudo mkdir -p /var/lib/dav
sudo mkdir -p /usr/uploads
sudo chown apache:apache /var/lib/dav
sudo chown apache:apache /usr/uploads

# Create digest password file with expect command.
sudo apk add expect
expect -c "
set timeout -1
spawn sudo htdigest -c /usr/user.passwd DAV-upload ${WEBDAV_USERNAME}
expect \"New password: \"
send \"${WEBDAV_PASSWORD}\n\"
expect \"Re-type new password: \"
send \"${WEBDAV_PASSWORD}\n\"
expect eof
"

2 Access to webdav

Install davfs2 package for mounting davfs.

$ sudo sed -e 's;^#http\(.*\)/v3\.8/community;http\1/v3.8/community;g' \
       -i /etc/apk/repositories
$ sudo apk update
$ sudo apk add davfs2

Get SSL certificate from server.

$ WEBDAV_SERVER_FQDN=webdav-server.hiroom2.com
$ openssl s_client -showcerts -connect "${WEBDAV_SERVER_FQDN}":443 \
< /dev/null 2> /dev/null | \
openssl x509 -outform PEM | \
sudo tee /etc/davfs2/certs/"${WEBDAV_SERVER_FQDN}".pem

Run "mount -t davfs".

$ sudo mount -t davfs https://${WEBDAV_SERVER_FQDN}/uploads /mnt
Please enter the username to authenticate with server
https://webdav-server.hiroom2.com/uploads or hit enter for none.
admin
  Username: Please enter the password to authenticate user admin with server
https://webdav-server.hiroom2.com/uploads or hit enter for none.
  Password:

Write file via webdav.

$ echo hello | sudo tee /mnt/hello.txt

For updating written file immediately, unmount /mnt.

$ sudo umount /mnt

Written file can be read in /usr/uploads.

$ sudo cat /usr/uploads/hello.txt
hello