Table of Contents
- Install the WebDAV module
- Configure the WebDAV directory
- Set up password authentication
- Configure an Apache vhost for WebDAV
- Test WebDAV
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
- 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:
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
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
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
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
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.
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:
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:
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:
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.