{"id":7565,"date":"2018-06-09T21:44:39","date_gmt":"2018-06-09T13:44:39","guid":{"rendered":"http:\/\/rmohan.com\/?p=7565"},"modified":"2018-06-09T21:45:43","modified_gmt":"2018-06-09T13:45:43","slug":"how-to-setup-a-webdav-server-using-apache-on-centos-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7565","title":{"rendered":"How to Setup a WebDAV Server Using Apache on CentOS 7"},"content":{"rendered":"<p><strong>How to Setup a WebDAV Server Using Apache on CentOS 7<\/strong><\/p>\n<p><strong>CentOS Linux Guides Server Apps Web Servers<\/strong><\/p>\n<p>WebDAV stands for &#8220;Web-based Distributed Authoring and Versioning&#8221;. It&#8217;s an extension of the HTTP protocol that allows users to manage and share files stored on a WebDAV-enabled web server.<\/p>\n<p>This tutorial will show you how to setup a WebDAV server using Apache on a Vultr CentOS 7 server instance.<\/p>\n<p>Prerequisites<br \/>\nA Vultr CentOS 7 server instance.<br \/>\nA non-root sudo user. You can learn more about how to create a sudo user in this Vultr tutorial.<br \/>\nStep one: Update the system<br \/>\nsudo yum install epel-release<br \/>\nsudo yum update -y<br \/>\nsudo shutdown -r now<br \/>\nAfter the reboot, use the same sudo user to log in.<\/p>\n<p>Step two: Install Apache<br \/>\nInstall Apache using YUM:<\/p>\n<p>sudo yum install httpd<br \/>\nDisable Apache&#8217;s default welcome page:<\/p>\n<p>sudo sed -i &#8216;s\/^\/#&amp;\/g&#8217; \/etc\/httpd\/conf.d\/welcome.conf<br \/>\nPrevent the Apache web server from displaying files within the web directory:<\/p>\n<p>sudo sed -i &#8220;s\/Options Indexes FollowSymLinks\/Options FollowSymLinks\/&#8221; \/etc\/httpd\/conf\/httpd.conf<br \/>\nStart the Apache web server:<\/p>\n<p>sudo systemctl start httpd.service<br \/>\nsudo systemctl enable httpd.service<br \/>\nStep three: Setup WebDAV<br \/>\nFor Apache, there are three WebDAV-related modules which will be loaded by default when a Apache web server getting started. You can confirm that with this command:<\/p>\n<p>sudo httpd -M | grep dav<br \/>\nYou should be presented with:<\/p>\n<p>dav_module (shared)<br \/>\ndav_fs_module (shared)<br \/>\ndav_lock_module (shared)<br \/>\nNext, create a dedicated directory for WebDAV:<\/p>\n<p>sudo mkdir \/var\/www\/html\/webdav<br \/>\nsudo chown -R apache:apache \/var\/www\/html<br \/>\nsudo chmod -R 755 \/var\/www\/html<br \/>\nFor security purposes, you need to create a user account, say it is &#8220;user001&#8221;, to access the WebDAV server, and then input your desired password. Later, you will use this user account to log into your WebDAV server.<\/p>\n<p>sudo htpasswd -c \/etc\/httpd\/.htpasswd user001<br \/>\nModify the owner and permissions in order to enhance security:<\/p>\n<p>sudo chown root:apache \/etc\/httpd\/.htpasswd<br \/>\nsudo chmod 640 \/etc\/httpd\/.htpasswd<br \/>\nStep four: Create a virtual host for WebDAV<br \/>\nsudo vi \/etc\/httpd\/conf.d\/webdav.conf<br \/>\nPopulate the file with:<\/p>\n<p>DavLockDB \/var\/www\/html\/DavLock<br \/>\n&lt;VirtualHost *:80&gt;<br \/>\nServerAdmin webmaster@localhost<br \/>\nDocumentRoot \/var\/www\/html\/webdav\/<br \/>\nErrorLog \/var\/log\/httpd\/error.log<br \/>\nCustomLog \/var\/log\/httpd\/access.log combined<br \/>\nAlias \/webdav \/var\/www\/html\/webdav<br \/>\n&lt;Directory \/var\/www\/html\/webdav&gt;<br \/>\nDAV On<br \/>\nAuthType Basic<br \/>\nAuthName &#8220;webdav&#8221;<br \/>\nAuthUserFile \/etc\/httpd\/.htpasswd<br \/>\nRequire valid-user<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;\/VirtualHost&gt;<br \/>\nSave and quit:<\/p>\n<p>:wq!<br \/>\nRestart Apache to put your changes into effect:<\/p>\n<p>sudo systemctl restart httpd.service<br \/>\nStep five: Modify firewall rules<br \/>\nsudo firewall-cmd &#8211;zone=public &#8211;permanent &#8211;add-service=http<br \/>\nsudo firewall-cmd &#8211;reload<br \/>\nStep six: Test the functionality of the WebDAV server from a local machine<br \/>\nIn 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:<\/p>\n<p>sudo yum install cadaver<br \/>\nHaving cadaver installed, use the following command to access the WebDAV server:<\/p>\n<p>cadaver http:\/\/&lt;your-server-ip&gt;\/webdav\/<br \/>\nUse the username &#8220;user001&#8221; and the password you setup earlier to log in.<\/p>\n<p>In the cadaver shell, you can upload and organize files as you wish. Here are some examples.<\/p>\n<p>To upload a local file &#8220;\/home\/user\/abc.txt&#8221; to the WebDAV server:<\/p>\n<p>dav:\/webdav\/&gt; put \/home\/user\/abc.txt<br \/>\nTo create a directory &#8220;dir1&#8221; on the WebDAV server:<\/p>\n<p>dav:\/webdav\/&gt; mkdir dir1<br \/>\nTo quit the cadaver shell:<\/p>\n<p>dav:\/webdav\/&gt; exit<br \/>\nIf you want to learn more about cadaver, you can look up the cadaver manual in the Bash shell:<\/p>\n<p>man cadaver<br \/>\nor<\/p>\n<p>cadaver -h<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Once it is done, you shall disable Apache&#8217;s default welcome page.<\/p>\n<p>[root@linuxhelp ~]# sed -i &#8216;s\/^\/#&amp;\/g&#8217; \/etc\/httpd\/conf.d\/welcome.conf<\/p>\n<p>Also, prevent the Apache web server from displaying files within the web directory.<\/p>\n<p>[root@linuxhelp ~]# sed -i &#8220;s\/Options Indexes FollowSymLinks\/Options FollowSymLinks\/&#8221; \/etc\/httpd\/conf\/httpd.conf<\/p>\n<p>After that, start and enable the Apache web server.<\/p>\n<p>[root@linuxhelp ~]# systemctl start httpd.service<br \/>\n[root@linuxhelp ~]# systemctl enable httpd.service<br \/>\nCreated symlink from \/etc\/systemd\/system\/multi-user.target.wants\/httpd.service to \/usr\/lib\/systemd\/system\/httpd.service.<br \/>\nSetup WebDAV<\/p>\n<p>For Apache, there are three WebDAV-related modules which will be loaded by default when an Apache web server is getting started.<\/p>\n<p>[root@linuxhelp ~]# httpd -M | grep dav<br \/>\ndav_module (shared)<br \/>\ndav_fs_module (shared)<br \/>\ndav_lock_module (shared)<\/p>\n<p>Next, create a dedicated directory for WebDAV:<\/p>\n<p>[root@linuxhelp ~]# mkdir \/var\/www\/html\/webdav<br \/>\n[root@linuxhelp ~]# chown -R apache:apache \/var\/www\/html<br \/>\n[root@linuxhelp ~]# chmod -R 755 \/var\/www\/html<\/p>\n<p>For security purposes, you need to create a user account.<\/p>\n<p>[root@linuxhelp ~]# htpasswd -c \/etc\/httpd\/.htpasswd user1<br \/>\nNew password:<br \/>\nRe-type new password:<br \/>\nAdding password for user user1<\/p>\n<p>And also, you need to modify the owner and permissions in order to enhance security<\/p>\n<p>[root@linuxhelp ~]# chown root:apache \/etc\/httpd\/.htpasswd<br \/>\n[root@linuxhelp ~]# chmod 640 \/etc\/httpd\/.htpasswd<\/p>\n<p>Once it is done, you need to create a VirtialHost for WebDAV.<\/p>\n<p>[root@linuxhelp ~]# vi \/etc\/httpd\/conf.d\/webdav.conf<br \/>\nDavLockDB \/var\/www\/html\/DavLock<br \/>\n&lt;VirtualHost *:80&gt;<br \/>\nServerAdmin webmaster@localhost<br \/>\nDocumentRoot \/var\/www\/html\/webdav\/<br \/>\nErrorLog \/var\/log\/httpd\/error.log<br \/>\nCustomLog \/var\/log\/httpd\/access.log combined<br \/>\nAlias \/webdav \/var\/www\/html\/webdav<br \/>\n&lt;Directory \/var\/www\/html\/webdav&gt;<br \/>\nDAV On<br \/>\nAuthType Basic<br \/>\nAuthName &#8220;webdav&#8221;<br \/>\nAuthUserFile \/etc\/httpd\/.htpasswd<br \/>\nRequire valid-user<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>Once the VirtualHost is configured, you need to restart Apache to put your changes into effect.<\/p>\n<p>[root@linuxhelp ~]# systemctl restart httpd.service<\/p>\n<p>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<\/p>\n<p>[root@linuxhelp ~]# yum install cadaver<br \/>\nLoaded plugins: fastestmirror, langpacks<br \/>\nLoading mirror speeds from cached hostfile<br \/>\n* base: mirror.dhakacom.com<br \/>\n* epel: mirror2.totbb.net<br \/>\n* extras: mirrors.viethosting.com<br \/>\n* updates: centos-hn.viettelidc.com.vn<br \/>\nResolving Dependencies<br \/>\n&#8211;&gt; Running transaction check<br \/>\n&#8212;&gt; Package cadaver.x86_64 0:0.23.3-9.el7 will be installed<br \/>\n&#8211;&gt; Finished Dependency Resolution<\/p>\n<p>.<br \/>\n.<br \/>\nRunning transaction<br \/>\nInstalling : cadaver-0.23.3-9.el7.x86_64 1\/1<br \/>\nVerifying : cadaver-0.23.3-9.el7.x86_64 1\/1<\/p>\n<p>Installed:<br \/>\ncadaver.x86_64 0:0.23.3-9.el7<\/p>\n<p>Complete!<\/p>\n<p>Having cadaver installed, use the following command to access the WebDAV server.<\/p>\n<p>[root@linuxhelp ~]# cadaver http:\/\/192.168.7.234\/webdav\/<br \/>\nAuthentication required for webdav on server `192.168.7.234&#8242;:<br \/>\nUsername: user1<br \/>\nPassword:<br \/>\ndav:\/webdav\/&gt;<\/p>\n<p>In the cadaver shell, you can upload and organize files as you wish. Here are some examples. To upload a local file<\/p>\n<p>dav:\/webdav\/&gt; put \/root\/Desktop\/linuxhelp.txt<br \/>\nUploading \/root\/Desktop\/linuxhelp.txt to `\/webdav\/linuxhelp.txt&#8217;: succeeded.<\/p>\n<p>To create a directory &#8220;dir1&#8221; on the WebDAV server<\/p>\n<p>dav:\/webdav\/&gt; mkdir dir<\/p>\n<p>To quit the cadaver shell<\/p>\n<p>dav:\/webdav\/&gt; exit<br \/>\nConnection to `192.168.7.234&#8242; closed.<br \/>\nIf 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Setup a WebDAV Server Using Apache on CentOS 7<\/p>\n<p>CentOS Linux Guides Server Apps Web Servers<\/p>\n<p>WebDAV stands for &#8220;Web-based Distributed Authoring and Versioning&#8221;. It&#8217;s an extension of the HTTP protocol that allows users to manage and share files stored on a WebDAV-enabled web server.<\/p>\n<p>This tutorial will show you how to setup [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7565"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7565"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7565\/revisions"}],"predecessor-version":[{"id":7568,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7565\/revisions\/7568"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}