WebDAV is for remote file Upload, manipulation, and editing Usage. WebDAV stands for Web Distributed Authoring and Versioning, which is an extension of HTTP that lets clients edit/view remote content on the web.
This tutorial will guide you on how you can enable WebDAV for your user accounts.
Hardness :Medium
Requirements (main) : php 7.1 and above and Apache webserver
Step 1 :
Download and install composer
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer chmod 755 /usr/local/bin/composer
Step 2 :
Install SabreDAV- WebDav php based
su -l username -s /bin/bash cd /home/username/public_html git clone https://github.com/sabre-io/dav.git cd dav /opt/alt/php-fpm71/usr/bin/php /usr/local/bin/composer install or "use your own php 7.1 bin path" /usr/local/bin/composer install mkdir data
**replace "username" with you User account name.
you can use PHP switcher or PHP selector or php-fpm
Now create an index.php file in dav directory
nano index.php
and add this script in it and save:
you can edit it like below to change the desired directory :
$rootDirectory = new DAV\FS\Directory('/home/username/public_html');
Fix the permission :
chmod 755 /home/username/public_html/dav chmod 644 /home/username/public_html/dav/index.php
Step 3 :
As root user now you need to enable the Apache WebDAV modules and it sub required modules :
mod_alias, mod_auth_digest, mod_authn_core, mod_authn_file, mod_authz_core, mod_authz_user, mod_dav, mod_dav_fs, mod_setenvif
got to /usr/local/apache/conf/httpd.conf and uncomment (remove the # from the first line of each required module) and uncomment (remove the # ) Include "conf/extra/httpd-dav.conf" file in httpd.conf
Next you also need to add the Directory directive to the domain/subdomain vhost which you want to activate webdav :
for ssl vhost :
<Directory "/home/username/public_html/dav"> AllowOverride All SSLRequireSSL Require all granted </Directory>
for non ssl vhost :
<Directory "/home/username/public_html/dav"> AllowOverride All Require all granted </Directory>
*** ensure you added this in main domain vhost i.e. usually under first one and in tag : <VirtualHost 1.1.1.1:443> </VirtualHost>
after changes restart httpd server :
systemctl restart httpd
Step 4 :
Adding authentication to webdav access
In user DAV domain dir /home/username/public_html/dav create .htaccess add this rules for digest auth and rewrite rule :
RewriteRule (.*) index.php [L] AuthType Digest AuthName "dav" AuthDigestDomain / AuthUserFile /home/username/.htpasswd Require user username-dav Satisfy All
**replace username with user account username
***replace username-dav with the dav user name you created with htdigest command below
And create .htpasswd in /home/username and add the digest auth, you need to use htdigest :
htdigest -c /home/username/.htpasswd dav admin
**replace username with user account username
enter the password when prompted.
eg :
admin:dav:595a268370390fe3e20cfffdd583d610here :-
username-dav : admin
realm : dav
pass : 595a268370390fe3e20cfffdd583d610
Step 5 :
Accessing webdav via domain
go to https://www.yourdomain.tld/dav or http://www.yourdomain.tld/dav
or you can use command line or webdav client in this eg I'm using cadaver package cli :
cadaver https://www.yourdomain.tld/dav