# 1.5 | WebDav

## Table Of Content
##

### WebDav Server Setup 

- https://helpcenter.onlyoffice.com/installation/groups-connect-webdav-ubuntu.aspx

1. Install the Apache web server
```
sudo apt-get update
sudo apt-get install apache2
```
Now the Apache server is installed and running.

2. Set the WebDAV data directory
The default document root directory for Apache (in Ubuntu 14.04 and later) is /var/www/html. It makes up the document tree structure which should be accessible from the web. Create a new folder named webdav within the /var/www/ directory:
```
sudo mkdir /var/www/webdav
```
Change the folder owner to your Apache user `www-data` so that Apache has write access to the folder:

```
sudo chown -R www-data:www-data /var/www/
```

3. Enable the WebDAV modules within the Apache configuration
Apache includes built-in WebDAV modules, but they are not enabled by default. Enable them using the following commands:

```
sudo a2enmod dav
sudo a2enmod dav_fs
```

4. Configure your WebDAV Server

https://helpcenter.onlyoffice.com/installation/groups-connect-webdav-ubuntu.aspx


```
DavLockDB /var/www/DavLock

<VirtualHost *:80>
        # WebDav Configurations 
        Alias /webdav /var/www/STORAGE
        <Directory /var/www/STORAGE> 
                DAV On 
                AuthType Basic
                AuthName "webdav" 
                AuthUserFile /etc/apache2/webdav.passwords 
                Require valid-user
                Options Indexes MultiViews
                AllowOverride None
        </Directory>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

```


### WebDav Client Setup 

- https://askubuntu.com/questions/406782/auto-mount-webdav-folder


1. Install davfs2 client to mount webdav
```
sudo apt install davfs2
```

2. add your user to `davfs` group so you can mount without `sudo` 
```
sudo usermod -a -G davfs2 $USER
```
You have to reboot/logout your system. OR execute the following before mounting the WebDav drive
```
su - $USER
```


3. Edit `/etc/davfs2/davfs2.conf` to enable automatic credentials use.

- Uncomment the line `secrets ~/.davfs2/secrets`

```
nano /etc/davfs2/davfs2.conf
```

4. Edit `~/.davfs2/secrets` file to add credentials to remote WebDav directory.

```
mkdir ~/.davfs2 ; nano ~/.davfs2/secrets
```

- Add a line to the end of file in following style:

```
https://<WebDav URI>   <username> <password>
```

```
http://aa.bb.cc.dd/webdav/ USER PASS
```


- Set the permission:
```
chmod 600 ~/.davfs2/secrets
```

5. Add a line to `/etc/fstab` about the remote WebDav directory

```
https://<WebDav URI> <mount point> davfs user,noauto,file_mode=600,dir_mode=700 0 1
```
```
[http://aa.bb.cc.dd/webdav/ /home/USER/STORAGE davfs _netdev,noauto,user,uid=USER,gid=USER  0       0
```

6. mount it 

Remember: Execute `su - $USER` If you didn't reboot/logout after adding the current user to `davfs2` group

- Linux
```
mount -t davfs -o noexec http://aa.bb.cc.dd/webdav/ /home/USER/STORAGE
```