[HOWTO] WebDAV via PHP

Questions and information regarding TeamDrive supported WebDAV servers - Fragen und Informationen zu von TeamDrive unterstützten WebDAV-Servern

[HOWTO] WebDAV via PHP

Postby virtualmachine » 12 Aug 2010, 12:35

Hello Everybody,

Sorry, but i accidently deleted my previous Post.

Please excuse my bad language. I'm german, but I wanted to make this Tutorial to be accessible by most of you.

I've found a way, how one could utilize his/her own Webspace to let PHP emulate the WebDAV Protocol. This means, that allmost every Webspace could be transformed into your personal Teamdrive /WebDAV Storage.

But first:
I am not the maintainer of this script! All credits got to Evert Pot for developing SabreDAV. The Project itself is hosted athttp://code.google.com/p/sabredav/.

Before I tell you, how you could utilize SabreDAV for your own needs, let me tell you about the Project itself:
SabreDAV is build on top of PHP and it emulates a standards compliant WebDAV Server. It is not only intendet to be a fileserver, you could even build it on top of a data structure, to fit your own needs. One Use-Case could be to make your Webapp populate the content as plain html via WebDAV. Or You could use it as a CalDAV Server to share corporate calendars. If you download the libs, several examples are included for many standard use cases.

We will utilize one of the example files, to engage digest authentication and even a file-browser plugin is implemented already. So you could use your newly created WebDAV Server both as storage for TeamDrive access and use it for file sharing. If you have advanced knowledge in PHP5, you could also establish very complex ACLs or Virtual Directories - But that is not part of my Tut.

Now, step by step:

1. Make sure, your Webspace is PHP5 enabled. If you are the Op, let me tell you, that you could use almost every Webserver like Nginx or even the fabulous lighttpd (produces lower Memory-Usage and could be run on older machines due to its lightweight architecture). My Setup is: Debian Lenny, Virtualmin powered, Apache2 and PHP5.2.x. My Excecution Environment relies on FastCGI.

2. Download the SabreDAV Sources.

3. Copy the contained folder SabreDAV to your Webspace.

3. Copy the file "fileserver.php" from the examples directory to your Document Root (I will NOT describe putting it in subfolder, tough it is possible. I have a dedicated Subserver (Apache vhost) for hosting and backing up files the easy way..

4. Rename it to index.php ( you could give it any name, but in my case, SabreDAV is the only application in this Document Root. It gets all the requests.)

5. Create 2 folder in your Document Root: tmpdata (for locks) and public (for the files) and make sure, they are writable for the Webserver

6. edit your index.php:


Code: Select all
    change your include path to
    set_include_path('SabreDAV/lib/' . PATH_SEPARATOR . get_include_path());




Code: Select all
 Change your default timezone:
    date_default_timezone_set('Europe/Berlin'); // Replace this with your own timezone



Code: Select all
    Before the line
    //$server->exec();

    //Enables content guessing Plugin
    $server->addPlugin(new Sabre_DAV_Browser_GuessContentType());





7. Create an empty file ".htdigest" file. You could implement your own Authentication Backend, but in this example, we will use the built in authentication.

8. Create a file called "echodigest.php" in your Document Root; this will echo the needed info for the .htdigest file. username and password are self explaining. SabreDAV is the realm.


Code: Select all
  <?php
    echo md5('your_username:SabreDAV:password');
    // Good practice to ommit the closing php-tag, to avoid compromised output.




9. Open the file echodigest.php via browser on your Webserver (http://www.example.com/echodigest.php) and copy the echoed content (it is a hash of the given values...).

9. insert a new line into your .htdigest file:


Code: Select all
username:SabreDAV:your_copied_hash




10. If you have a server running in FastCGI mode (if you do, accessing your example.com/index.php will not accept your credentials), you also have to create a ".htaccess" file with the following content (taken from the SabreDAV wiki.. works for my setup):


Code: Select all
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    </IfModule>




11. Access your new WebDAV Server via the browser (e.g. files.yourdomain.com/index.php/). If you consulted the SabreDAV Wiki, you could utilize mod_rewrite to route all requests to your index.php and omit the index.php - part.

12. If the previous step was successful, connect TeamDrive to files.yourdomain.com/index.php/

13. You are up and running! Think about the enormous possibilities, SabreDAV offers! It is much more powerful than this and delivers all needed interfaces to enhance it to suit your needs. Think of LDAP authentication, or storage inside your RDMS. Think even of enhancing your application to support WebDAV.

Okay, thats it. Id like to respond to questions. I would like to maintain this thread.. But think of contributing to SabreDAV, and maybe thank Evert Pot for this fabulous piece of Software!

I added an example package. Just upload to your Document root and the folder "SabreDAV" contained in the Source package from http://code.google.com/p/sabredav/downloads/list. Default user is test/test. Change it to fit your needs via editing .htdigest in common with echodigest.php
Attachments
SabreDAV-example.zip
Example Package
(1.49 KiB) Downloaded 1076 times
virtualmachine
 
Posts: 4
Joined: 09 Aug 2010, 23:11

Re: [HOWTO] WebDAV via PHP

Postby Fardilha » 22 Apr 2012, 12:36

Hi there.

Just wanted to thank you for pointed to such a great project!
It worked really well under my setup and I'm finally able to use TeamDrive with my server.

Thank you once again.
Fardilha
Fardilha
 
Posts: 10
Joined: 15 Aug 2009, 16:46


Return to WebDAV Server - WebDAV-Server

Who is online

Users browsing this forum: No registered users and 10 guests

cron