Tutorials

How to Set up WebDAV with Apache on CentOS 7

Table of Contents

Introduction

WebDAV (Web-based Distributed Authoring and Versioning) is an extension of the HTTP protocol that allows users to edit and manage documents and files stored on web servers.

WebDAV provides a framework for users to create, change, move, upload, and download documents on an Apache web server. This makes WebDAV a popular choice for developers, especially when combined with Subversion or Git.

You can easily mount WebDAV's data storage to the local filesystem. This can be done with the mount command or with a WebDAV-supported file manager such as Nautilus or Konqueror.

In this article I will explain some quick and easy steps to set up WebDAV with Apache on CentOS 7

Requirements

  • A server running CentOS v. 7 with Apache installed
  • A static IP address for your server

Install the WebDAV module

The WebDAV module is included with the apache2 installation in CentOS 7, and is enabled by default. You can verify that the WebDAV module is running by using the following command:

sudo httpd -M | grep fs

If WebDAV is enabled, you will see the following output:

dav_fs_module (shared)

Configure the WebDAV directory

After installing the WebDAV module, you will need to create a webdav directory. Here, we will create the webdav directory under the Apache web root directory.

sudo mkdir /var/www/html/webdav

Next, change the ownership (to the apache user) and the permissions for the webdav directory with the following commands:

sudo chown -R apache:apache /var/www/html/webdav
sudo chmod -R 755 /var/www/html/webdav

Set up password authentication

It is important to secure your webdav directory with a password. You can do this by creating an .htpasswd file.

To create it, run the following command:

sudo htpasswd -c /etc/httpd/.htpasswd dev

This will create a password file for the user dev.

Now, you need to assign group ownership of the file to the apache user, and lock down the permissions for everyone else. To do this, run the following command:

sudo chown root:apache /etc/httpd/.htpasswd
sudo chmod 640 /etc/httpd/.htpasswd

Configure an Apache vhost for WebDAV

Next, you need to create a virtual host file for the webdav directory. Start by creating a new site configuration file called webdav.conf.

sudo nano /etc/httpd/conf.d/webdav.conf

Add the following content:

DavLockDB /var/www/html/DavLock
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/webdav/
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
        Alias /webdav /var/www/html/webdav
        <Directory /var/www/html/webdav>
            DAV On
            AuthType Basic
            AuthName "webdav"
            AuthUserFile /etc/httpd/.htpasswd
            Require valid-user
        </Directory>
</VirtualHost>

Now, restart Apache to activate the new configuration:

sudo apachectl restart

Test WebDav

Finally, WebDAV is ready for testing. Here, we will use a browser and a client to check WebDAV.

Test with a web browser

To test whether the authentication is working correctly or not, open your web browser and navigate to the URL http://your.server.ip/webdav/.

Apache password prompt when testing WebDAV

You will be prompted for a user name and password to access WebDAV. Here, you will need to enter the user name and password we set before.

Enter username and password for Apache authentication

Test with a command line client

Here, we will use a WebDAV client called Cadaver. To install Cadaver, use the command below:

sudo yum --enablerepo=epel install cadaver

After installing Cadaver, you can test your WebDAV using the command below:

cadaver http://your.server.ip/webdav/

Apache login using Cadaver

If all went well, you will be asked to enter your user name and password for WebDAV. Then, You should be granted access which means that WebDAV is working correctly.

Some useful Cadaver command examples are listed below:

To upload a file to WebDAV:

dav:/webdav/> put filename

To view/list the contents on WebDAV:

dav:/webdav/> ls

To create a new directory and navigate to it:

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

Once you are done, you can exit using the below command:

dav:/webdav/> exit

Conclusion

Finally, we have successfully set up WebDAV with Apache Web Server on CentOS 7. You can also experiment with WebDAV in your virtual environment. If you have any questions, you can write them in the comment box below.

Enjoy......

 
  • 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

  • Hi, I was also following the tutorial and run into the same issue, I was unable to create folders and files. After 2 days of suffering, I found that SELinux is enabled on our CentOS system, which prevents httpd process to write on local disk, no matter what file permissions are set.

    $ chcon -R -t httpd_sys_content_t /path/to/www $ chcon -R -t httpd_sys_rw_content_t /path/to/www/dir/for/rw

    You can read the original post here: https://stackoverflow.com/questions/28856148/centos-7-apache-php-mkdir-permission-denied

  • Hello,

    i installed everthing on my CentOS 7 server, but i got the following error:

    Invalid command 'vLockDB', perhaps misspelled or defined by a module not included in the server configuration

    what did i do wrong?

    thanks in advance

  • Sorry for Doubleposting but there is no editing function.

    When i do as written - > Trying to access http://$ip$/ i need to type in the password.

    I do only want the .htaccess for the http://$ip$/webdav/ directory.

    where is the mistake? thanks everbody

Log In, Add a Comment