Artigos‎ > ‎Compartilhamento de Arquivos‎ > ‎WebDav‎ > ‎

Apache WebDav no Ubuntu


Link: http://www.digital-arcanist.com/sanctum/article.php?story=20070427101250622

This HOWTO will show you how to create WebDAV enabled directories hosted on your Apache webserver. I wrote this using Ubuntu Server 7.04, but it should work on previous Ubuntu releases and (with only minor modifications) any other Linux distro.

  1. What is WebDAV?
  2. WebDAV stands for Web-based Distributed Authoring and Versioning. It was designed to allow groups of individuals to edit and manage files stored on a web-server. The protocol allows the creation of "web-shares" which can be used for file storage, collaborative projects, editing websites themselves, and any number of other things. WebDAV supports features like editing, copying, and moving of files, file locks, resource lists, and file property modification. Most operating systems, including MS Windows, support WebDAV directories.
  3. Install the Proper Software
  4. The first thing you will need (obviously) is a functioning apache2 webserver. If you happened to have install Ubuntu Server Edition with the LAMP option, then you're set. Otherwise, you'll need to get a few things with apt. Do this however you want; I will use the command line. While you're at it, you might as well get PHP to go with it.

    apt-get install apache2 php5 libapache2-mod-php5
  5. Add Modules
  6. Fortunately, Apache 2.x comes with mod_dav already installed, we just have to activate it. We can do this by making some symlinks.

    cd /etc/apache2/mods-enabled
    ln -s ../mods-available/dav* .
  7. Create LockDB file for WebDAV
  8. Next we need to set up a DAVLockDB file for WebDAV to use. This is a very important step, as you'll wind up with Internal Server Errors if you try to use WebDAV without it.

    mkdir /usr/share/apache2/var
    touch /usr/share/apache2/var/DAVLock
    chown -R www-data:www-data /usr/share/apache2/var
  9. Setup Authentication and Add Users
  10. WebDAV can open your web server up to security risks. You don't want just anyone to wander in and change your files! There are several ways you can do authentication for your WebDAV directory, but htpasswd is the easiest and probably best for most cases. We'll make the passwords using MD5 and store them where we store the apache configurations and add an initial user while we're at it.

    htpasswd -m -c /etc/apache2/.htpasswd
    You can use this command to add more users later or change their passwords. Just remember to remove the -c option or you'll truncate your password db every time!
  11. Create the WebDAV Directory
  12. Okay, almost done. Let's make a directory in our web document root where we will run our WebDAV. I'm calling it myWebDAV. This is the folder in which your authorized users will be able to add, delete, and modify files. The directory will need to be writable by the web server.

    mkdir /var/www/myWebDAV
    chown www-data:www-data /var/www/myWebDAV
  13. Configure Apache
  14. Now all we need to tell Apache how to use WebDAV and where to enable it. This consists of adding a few definitions to the user-defined config file at /etc/apache2/httpd.conf. Open that file with an editor and add lines similar to those below.

    ## Location of the DavLock file
    DavLockDB /usr/share/apache2/var/DavLock

    ## Set up the myWebDAV directory to use WebDAV and authentication

    Dav On
    AuthName "WebDAV Login"
    AuthType Basic
    AuthUserFile /etc/apache2/.htpasswd
    ## Limit access for enhanced security

    require valid-user

    Order allow,deny
    Allow from all

  15. Restart Apache and Test
  16. That's it! Restart your web server and you're good to go. You and your friends/coworkers/etc can now login and modify the files at http://your.domain.com/myWebDAV.

    /etc/init.d/apache2 restart
Comments