How To Setup WebDAV With Apache Web Server on Fedora 21

Hi everyone, today we'll learn how to setup WebDav with Apache2 Web Server on Fedora 21 Operating System. WebDAV stands for "Web-based Distributed Authoring and Versioning". It is a set of extensions to the HTTP protocol which allows users to collaboratively edit and manage files on remote web servers. The WebDAV protocol makes the Web a readable and writable medium. It provides a framework for users to create, change and move documents on a server; typically a web server or web share. The most important features of the WebDAV protocol include the maintenance of properties about an author or modification date, namespace management, collections, and overwrite protection. Maintenance of properties includes such things as the creation, removal, and querying of file information.

Here are some quick and easy steps  to setup WebDav with Apache Web Server on Fedora 21.

 1. Installing Apache Web Server

First of all, we'll need to make sure that Apache Web Server is installed on our system. If its not installed, we'll need to install by running the following command.

$ sudo yum install httpd

Installing httpd on fedora

Now, after we install Apache Web Server, we'll want to enable it to startup in every boot and start the service.

$ sudo systemctl enable httpd.service
$ sudo systemctl start httpd.service

Enabling httpd

2. Configuring WebDav Directory

After installing Apache Web Server, we'll now create the required directory where we'll configure webdav in. Here, we've choosed /var/www/linoxide/webdav as WebDav enabled directory.

$ sudo mkdir -p /var/www/linoxide/webdav

Then, we'll want to make user "apache" having group "apache" as the owner of the directory using the following command.

$ sudo chown apache:apache /var/www/linoxide/webdav

configuring webdav directory

3. Setting Password Protection

We can create an authentication procedure for accessing the directory content by creating an htpasswd file. To create it, we need to run the following command in a shell or a terminal.

$ sudo htpasswd -c /var/www/linoxide/passwd.dav admin

Note: Here, admin is a username, you can change it as per the security.

After running the above command, we'll be asked to enter a password for the user admin .

setting password protection

Right now, anyone can view the username and hashed password in the file. We will assign group ownership of the file to apache and then lock down the permissions for everyone else:

$ sudo chown root:apache /var/www/linoxide/passwd.dav
$ sudo chmod 640 /var/www/linoxide/passwd.dav

fixing dav password permission

 4. Configuring Apache Vhost

Now, we'll configure our Apache Web Server's vhost configuration. To do that, we'll need to open the config file using our favorite text editor.

$ sudo nano /etc/httpd/conf/httpd.conf

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/linoxide/webdav/
<Directory /var/www/linoxide/webdav/>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /webdav /var/www/linoxide/webdav/
<Location /webdav>
DAV On
AuthType Basic
AuthName "webdav"
AuthUserFile /var/www/linoxide/passwd.dav
Require valid-user
</Location>
</VirtualHost>

apache configuration for webdav

Now, after configuring the config file, we'll want to restart our Apache Web Server.

$ sudo systemctl restart httpd.service

restarting httpd service

5. Testing WebDav

To test whether WebDav is properly enabled or not, we'll use a browser and a client to check.

Test using a Web Browser

To test if the authentication is working correctly or not, we'll navigate to our server's IP address or domain name using our favorite web browser.

We'll need to navigate to http://our_IP_address_or_domain/webdav . Then, everything worked fine as illustrated, a prompt for the username and password should appear. Here, we'll need to enter the username and password we set before.

webdav login browser test

Test using a Client

We'll use a WebDav client called cadaver. To install it in our Fedora 21 Server, we'll need to run the following command.

$ sudo yum install cadaver

After installing cadaver, we'll test our webdav using the command below.

$ cadaver http://your_IP_address_or_domain/webdav

If all went well, we'll be asked to enter our username and password we kept before. Then, We should be granted access which means WebDAV is working fine.

Now, we can operate the client and host at the same time using commands that are similar to regular Linux commands. Some of the useful examples are as follows.

To upload

dav:/webdav/> put file

To view/list the contents

dav:/webdav/> ls

To create a new directory and to navigate

dav:/webdav/> mkdir new-dir
dav:/webdav/> cd new-dir

To create files

dav:/webdav/> edit index.html
<h1>Hi!!!</h1>

Now, after done, we can exit using the below command.

dav:/webdav/> exit

Conclusion

Finally, we have successfully set up WebDav with Apache Web Server on our Fedora 21. WebDav is an awesome security module by Apache2 which is a set of extensions to the HTTP protocol which allows users to collaboratively edit and manage files on remote web servers.  So, if you have any questions, suggestions, feedback please write them in the comment box below. Thank you ! Enjoy  :-)

About Arun Pyasi

Linux Enthusiast geek and Web Developer who loves Free and Open Source Software (FOSS). He is a FOSS activist who loves technology, hacking, blogging, travelling, research and development. He is the Founder/Lead Developer of Chitwanix OS.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

4 Comments

  1. Hi, I followed your tutorial exactly step by step. Looks like it is working for me but I have one issue with permission. In Cadaver I am getting dav:/webdav/> mkdir testing Creating `testing': failed: 403 Forbidden

    I can't create files. Could you please help me? Thanks

    1. Have you verified the ownership fo your webdav directory on your server? It must be apache:apache on Redhat based distros (Fedora, CentOS) or www-data on Debian based distros (Ubuntu, Raspbian). The permissions should be 775 (drwxr-xr-x). Without it you will not be allowed to create directories and files.

  2. This is a nice tutorial but you should take more care about security. The password file _must not_ reside in the directory shared by WebDAV. It is too easy to change its permissions by mistake and then tha password hashes will be exposed. Such files must always reside outside the document root. You can also use your global user and group files. Your group file may for instance contain

    webdav:joe jack judy

    The passwords for users joe, jack, and judy will be created as written in the tutorial. The permissions for the webdav directory will then be set as

    AuthUserFile /outside/document/root/user
    AuthGroupFile /outside/document/root/group
    Require group webdav

    The rest will remain the same as shown in the tutorial.
    The user names and passwords are transferred as clear texts over the network. You should consider using https instead of http.

  3. Fedora now comes with the davfs2 package which allows to mount the webdav directory exactly as any external device. You install it by

    dnf install davfs2

    Then you add the following to /etc/fstab:

    http://your_IP_address_or_domain/webdav /home/myself/webdav davfs rw,user,noauto 0 0

    You have to create the webdav directory in your home. Then you can just mount it by

    cd
    mount webdav

    You will be asked to supply your username and password. If your computer is secure, you can insert these data into ~/.davfs2/secrets in the following form

    http://your_IP_address_or_domain/webdav username password

    And consider using https instead of http.