How to Setup a WebDAV Server Using Apache on CentOS 7

To Setup a WebDAV Server Using Apache on CentOS 7

WebDAV stands for " Web-based Distributed Authoring and Versioning" . It' s an extension of the HTTP protocol that allows users to manage and share files stored on a WebDAV-enabled web server.  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 setup WebDAV via Apache on your CentOS machine and this tutorial covers the ground on the same method. 

 

Setting Up a WebDAV Server

First, make sure you update the system by making use of the following command. 

[root@linuxhelp ~]# yum install epel-release
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * extras: mirrors.vonline.vn
 * updates: mirrors.vhost.vn
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-9 will be installed
-->  Finished Dependency Resolution
.
.
Running transaction
  Installing : epel-release-7-9.noarch                                                     1/1 
  Verifying  : epel-release-7-9.noarch                                                     1/1 
Installed:
epel-release.noarch 0:7-9                             


Once it is done, make sure you the system with the help of the following command. 

[root@linuxhelp ~]# yum update -y
' Loaded plugins: fastestmirror, langpacks
epel/x86_64/metalink                                                    | 7.4 kB  00:00:00     
epel                                                                    | 4.7 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                             | 266 kB  00:00:01     
(2/3): epel/x86_64/updateinfo                                           | 892 kB  00:00:11     
(3/3): epel/x86_64/primary_db                                           | 6.2 MB  00:00:16     
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: mirror2.totbb.net
 * extras: mirrors.vonline.vn
 * updates: mirrors.vhost.vn
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-9 will be updated
--->  Package epel-release.noarch 0:7-11 will be an update
-->  Finished Dependency Resolution
.
.
Running transaction
  Updating   : epel-release-7-11.noarch                                                    1/2 
  Cleanup    : epel-release-7-9.noarch                                                     2/2 
  Verifying  : epel-release-7-11.noarch                                                    1/2 
  Verifying  : epel-release-7-9.noarch                                                     2/2 

Updated:
  epel-release.noarch 0:7-11                                                                   
Complete!

 

After that, you shall trigger the following command to install Apache. 

[root@linuxhelp ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: ftp.cuhk.edu.hk
 * extras: mirrors.viethosting.com
 * updates: centos-hn.viettelidc.com.vn
Resolving Dependencies
-->  Running transaction check
--->  Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be installed
-->  Processing Dependency: httpd-tools = 2.4.6-67.el7.centos.6 for package: httpd-2.4.6-67.el7.centos.6.x86_64
.
.
Installed:
  httpd.x86_64 0:2.4.6-67.el7.centos.6                                                                                                       

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1   apr-util.x86_64 0:1.5.2-6.el7   httpd-tools.x86_64 0:2.4.6-67.el7.centos.6   mailcap.noarch 0:2.1.41-2.el7  

Complete!


Once it is done, you shall disable Apache' s default welcome page.

[root@linuxhelp ~]# sed -i ' s/^/#& /g'  /etc/httpd/conf.d/welcome.conf

 

Also, prevent the Apache web server from displaying files within the web directory. 

[root@linuxhelp ~]# sed -i " s/Options Indexes FollowSymLinks/Options FollowSymLinks/"  /etc/httpd/conf/httpd.conf

 

After that, start and enable the Apache web server.

[root@linuxhelp ~]# systemctl start httpd.service 
[root@linuxhelp ~]# systemctl enable httpd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Setup WebDAV


For Apache, there are three WebDAV-related modules which will be loaded by default when an Apache web server is getting started. 

[root@linuxhelp ~]# httpd -M | grep dav
 dav_module (shared)
 dav_fs_module (shared)
 dav_lock_module (shared)


Next, create a dedicated directory for WebDAV:

[root@linuxhelp ~]# mkdir /var/www/html/webdav
[root@linuxhelp ~]# chown -R apache:apache /var/www/html
[root@linuxhelp ~]# chmod -R 755 /var/www/html

 

For security purposes, you need to create a user account. 

[root@linuxhelp ~]# htpasswd -c /etc/httpd/.htpasswd user1
New password: 
Re-type new password: 
Adding password for user user1

 

And also, you need to modify the owner and permissions in order to enhance security

[root@linuxhelp ~]# chown root:apache /etc/httpd/.htpasswd
[root@linuxhelp ~]# chmod 640 /etc/httpd/.htpasswd


Once it is done, you need to create a VirtialHost  for WebDAV.

[root@linuxhelp ~]# vi /etc/httpd/conf.d/webdav.conf 
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> 


Once the VirtualHost is configured, you need to restart Apache to put your changes into effect. 

[root@linuxhelp ~]# systemctl restart httpd.service

 

Test the functionality of the WebDAV server from a local machine.  In order to take advantage of WebDAV, you need to use a qualified client. For example, you can install a program called cadaver on a CentOS 7 desktop

[root@linuxhelp ~]# yum install cadaver
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: mirror2.totbb.net
 * extras: mirrors.viethosting.com
 * updates: centos-hn.viettelidc.com.vn
Resolving Dependencies
-->  Running transaction check
--->  Package cadaver.x86_64 0:0.23.3-9.el7 will be installed
-->  Finished Dependency Resolution

.
.
Running transaction
  Installing : cadaver-0.23.3-9.el7.x86_64                                                                                               1/1 
  Verifying  : cadaver-0.23.3-9.el7.x86_64                                                                                               1/1 

Installed:
  cadaver.x86_64 0:0.23.3-9.el7                                                                                                              

Complete! 

 

Having cadaver installed, use the following command to access the WebDAV server.

[root@linuxhelp ~]# cadaver http://192.168.7.234/webdav/
Authentication required for webdav on server `192.168.7.234' :
Username: user1
Password: 
dav:/webdav/> 

 

In the cadaver shell, you can upload and organize files as you wish. Here are some examples. To upload a local file

dav:/webdav/>  put /root/Desktop/linuxhelp.txt 
Uploading /root/Desktop/linuxhelp.txt to `/webdav/linuxhelp.txt' : succeeded.

 

To create a directory " dir1" on the WebDAV server

dav:/webdav/>  mkdir dir

 

To quit the cadaver shell

dav:/webdav/>  exit
Connection to `192.168.7.234'  closed.

If you want to learn more about cadaver, you can look up the cadaver manual in the Bash shell. With this, the tutorial on setting up a WebDAV Server Using Apache on CentOS 7 comes to an end. 

FAQ
Q
What are the WebDAV-related modules available?
A
The avilable WebDAV-related modules were

dav_module (shared)
dav_fs_module (shared)
dav_lock_module (shared)
Q
How to disable default apache welcome page from command line?
A
you can disable the default apache welcome page using the following command

#sed -i ' s/^/#& /g' /etc/httpd/conf.d/welcome.conf
Q
How to access webdav after the setup ?
A
To access webdav after the setup cadaver navigate to the following localhost/webdav
Q
What is the command to install cadaver for WebDAV Server setup using apache?
A
The command to install cadaver for WebDAV Server setup using apache is

#yum install cadaver
Q
What is webdav and its uses?
A
WebDAV stands for " Web-based Distributed Authoring and Versioning" . It' s an extension of the HTTP protocol that allows users to manage and share files stored on a WebDAV-enabled web server.