Enable WebDAV on Linux
WebDAV (acronym for Web Distributed Authoring and Inersioning) is an HTTP protocol extension that enables clients to perform operations on the remote server.
WebDAV is nothing new, it was first introduced in 1996 and it has been the standard ever since de facto of many web applications.
WebDAV is directly dependent on and connected to Apache2. However, by installing the webserver we will not automatically enable WebDAV as well. By the end of this article you will know how to activate WebDAV on a Linux computer. We assume that on the PC in question there is already an active and functioning LAMP installation. I'll use Ubuntu for the occasion 20.04 LTS.
First we enable the modules necessary for the functioning of WebDAV. We open a terminal and type:
~$ sudo a2enmod dav ~$ sudo a2enmod dav_fs
We restart the web server with the command:
~$ sudo /etc/init.d/apache2 restart
Virtual host configuration
In the next step you will create the necessary environment for the host to operate: specific directories, related permissions, changes to the file
.conf in Apache.
We will now create the root directory. For simplicity we will call it
~$ sudo mkdir -p /var/www/webdav
It is important that the owner of the directory and all content is Apache:
~$ sudo chown www-data.www-data /var/www/webdav
In the next step we will create a file
.conf which will contain instructions for Apache for it to “notice” of the virtual host:
~$ sudo nano /etc/apache2/sites-available/webdav.conf
The contents of the file:
NameVirtualHost * <VirtualHost *:80> ServerAdmin webmaster@domain DocumentRoot /var/www/webdav/ <Directory /var/www/webdav/> Options Indexes MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> Alias /webdav /var/www/webdav <Location /webdav> DAV On AuthType Basic AuthName "webdav" AuthUserFile /var/www/webdav/passwd.dav Require valid-user </Location>
Note the local address “
webmaster@domain“. You will need to enter the real address of the site administrator. Now let's save and close the file with
ctrl + o and
ctrl + c.
Let's copy the webdav.conf file from “sites available” to “enabled sites” with this command:
~$ sudo a2ensite webdav.conf
Before restarting Apache we need to create a password to access the WebDAV shares (
USER must be a user of the system):
~$ sudo htpasswd -c /var/www/webdav/passwd.dav USER
Now that the
passwd.dav containing the password we must make it accessible and visible only to the system administrator
root and group members
~$ sudo chown root:www-data /var/www/webdav/passwd.dav ~$ sudo chmod 640 /var/www/webdav/passwd.dav
We restart Apache with the previous command:
~$ sudo /etc/init.d/apache2 restart
If everything went as planned, the system should be active.
Testing a WebDAV installation is very simple. There is a simple tool to install and use for this purpose: Cadaver.
~$ sudo apt install cadaver
Once installed, launching it is even easier:
~$ cadaver http://IP_DEL_SERVER/webdav
The system should now ask for user and password. We enter the configured user name and the relative password. If all went well, a prompt like this will be shown:
Now that the installation has gone smoothly, we can connect WebDAV to any tool that supports it as desired. As already mentioned WebDAV is a not new project that has become a standard over the years and is natively supported by all operating systems (without installing third-party drivers or software). Just write the WebDAV server address in the address bar of any file manager that the operating system is Windows, Mac, Linux, or mobile devices. After prompting for credentials, in all cases a position will be mounted on which we can operate as if it were a local resource (like a USB stick).
WebDAV can be used as a collaborative suite (this was originally the purpose of the project), but most of its application today is as remote storage. WebDAV is a service that can be activated on most NAS and even some hosts have a service running on it (for example cPanel has a module called Web Disk… guess what it is). It is a very tested software, open source and reliable and if I were to start a project that involves linking multiple collaborators into a single project it would be my first preference.