Jun 22, 2023

Ubuntu : Apache2's Module - WebDAV

WebDAV (Web Distributed Authoring and Versioning) is a set of extensions to the HTTP (HyperText Transfer Protocol) which allows Users to collaboratively author contents directly in HTTP web server by providing facilities for concurrency control and namespace operations.

In this tutorial, we will focus on the Installation and Configuration of WebDAV via Ubuntu Server v.22.04.2 and Apache2 Web Server.

For more information on How-To install Ubuntu Server, please refer here (https://danielcheah.blogspot.com/2023/03/linux-install-ubuntu-server-v22041.html)

For more information on How-To install Apache2 Server, please refer here (https://danielcheah.blogspot.com/search/label/Apache)

1) Enabled Apache2's WebDAV module:

 sudo a2enmod dav


 sudo a2enmod dav_fs



2) Restart Apache2 service:

 sudo systemctl restart apache2



3) Create a new folder in Apache2:

 sudo mkdir /var/www/webdav



4) Change ownership for that new folder:

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



5) Create another new folder to store the WebDAV's DB file and change the ownership:

 sudo mkdir -p /usr/local/apache/var


 sudo chown www-data:www-data /usr/local/apache/var



6) Modify the Virtual Host file for the domain (eg. demo.gob.com.my):

 sudo nano /etc/apache2/sites-enabled/demo.gob.com.my.conf

* The file name depends on your domain name created during installation of Apache2.


7) Add the following content into the Virtual Host file as below, as per in "RED" text:
DavLockDB /usr/local/apache/var/DavLock

<VirtualHost *:80>
    ServerAdmin demo@localhost
    ServerName demo.gob.com.my
    ServerAlias www.demo.gob.com.my
    DocumentRoot /var/www/demo.gob.com.my
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /webdav /var/www/webdav

    <Directory /var/www/webdav>
        DAV ON
        AuthType Digest
        AuthName "webdav"
        AuthUserFile /usr/local/apache/var/users.password
        Require valid-user
    </Directory>

</VirtualHost>



8) Check the Apache2 configuration and restart the service:

 sudo apache2 configtest


 sudo systemctl restart apache2



9) Now we need to create a file to store all Username and change the ownership of the file:

 sudo touch /usr/local/apache/var/users.password


 sudo chown www-data:www-data /usr/local/apache/var/users.password



10) Create the first Username and its corresponding password:

 sudo htdigest -c /usr/local/apache/var/users.password webdav demo

* webdav --> Realm
* demo --> Username
* It will automatically prompt you to key-in the password for the new user.


11) Enable Apache2's Digest Authentication module:

 sudo a2enmod auth_digest



12) Restart Apache2 service:

 sudo systemctl restart apache2



13) Now create a dummy file for testing purposes and assign the appropriate ownership:

 sudo nano /var/www/webdav/testfile.txt

* Type some text into that file.

 sudo chown www-data:www-data /var/www/webdav/testfile.txt



14) To verify the connection, open any inter browser (eg. Google Chrome) and browse to (eg. http://demo.gob.com.my/webdav)

You should be prompted with a username and password, continue to key-in the username (eg. demo) and the password.

Upon successful login, you will able to view the dummy file created earlier and able to download/access the file accordingly as per below screenshot.


WebDAV Dummy File


15) You can also map a network drive by using the same URL / Path and with the same username and password.





!!! HAPPY COMPUTING !!!