|
GettingStarted
Quick setup for SabreDAV
InstallationTo use SabreDAV you'll need a recent version of PHP 5.2. At a minimum you currently need the DOM and the XMLWriter extensions. In most cases this is installed by default, but if this is not the case, you might have to go to pecl. SabreDAV has been tested with:
You can start with SabreDAV by simply downloading the package from the downloads section and unpacking it Make sure that the path to the package is referenced in your include_path setting. Initial setupCreate two directories in your top directory, and name them 'data' and 'public'. Public is going to contain the files and directories we're going to share using WebDAV, data is a folder SabreDAV needs to store additional information. Make sure both folders are writable by the username the webserver is running as. Depending on your operation system this could be the 'www-data', 'apache', 'httpd' or 'nobody' user. To start off with SabreDAV you need your base index.php (or otherwise) start file. This is an example of such a file: <?php
// Files we need
require_once 'Sabre.autoload.php';
// Now we're creating a whole bunch of objects
// Change public to something else, if you are using a different directory for your files
$rootDirectory = new Sabre_DAV_FS_Directory('public');
// The tree manages all the file objects
$tree = new Sabre_DAV_ObjectTree($rootDirectory);
// Finally, we create the server object. The server object is responsible for making sense out of the WebDAV protocol
$server = new Sabre_DAV_Server($tree);
// If your server is not on your webroot, make sure the following line has the correct information
// $server->setBaseUri('/~evert/mydavfolder'); // if its in some kind of home directory
// $server->setBaseUri('/dav/index.php/'); // if you can't use mod_rewrite, use index.php as a base uri
// $server->setBaseUri('/'); // ideally, SabreDAV lives on a root directory with mod_rewrite sending every request to index.php
// The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different directory, if you're storing your data somewhere else.
$lockBackend = new Sabre_DAV_Locks_Backend_FS('data');
$lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend);
$server->addPlugin($lockPlugin);
// All we need to do now, is to fire up the server
$server->exec();
?>Client SetupNow you have your SabreDAV installation running. You can open it up in the browser to see if everything went as expected. The following error should be displayed: <?xml version="1.0"?> <d:error> <s:exception>Sabre_DAV_Exception_NotImplemented</s:exception> <s:message>GET is only implemented on File objects</s:message> <s:file>/SabreDAV/lib/Sabre/DAV/Server.php</s:file> <s:line>291</s:line> <s:code>0</s:code> </d:error> If you see anything else, something went wrong during setup. Now you can connect to the WebDAV server using your client. For more details, check the Client-specific pages:
Trouble ShootingWebDAV servers can be hard to debug, because the error messages reported by clients are often generic and cryptic. It is highly recommended to use a debugging proxy to find out whats going on over the wire. If your application returns an error, the debugging proxy is the tool to reveal it. Some tools:
Thats itWell, almost.. This WebDAV folder is wide open, everybody can read and write. Implement HTTP authentication to lock it down. This is not part of the SabreDAV distribution (yet). Next steps
|
Sign in to add a comment
I have an error : Call to undefined method Sabre_DAV_FS_Directory::get()
Hi emmanuel,
You'll get that error when you try to open your sabredav installation through a webbrowser, which is not how its intended to be used..
Give it a shot using Finder (if you're on a mac) or DavFS2 (if you're on linux..) I realize I didn't include this in this tutorial, so I'll add that in..
Thanks
After following these instructions my httpd spins out of control, repeatedly crashing every few seconds, even though it was minutes since I stopped trying to connect to the DAV server.
Apache/2.2.6 (installed with Darwin Ports on Mac OS X 10.5.2 connecting with Finder)
This is the message in apache's error_log:
child pid 16418 exit signal Segmentation fault (11)
Thats a nasty one, and usually means PHP goes into some infinite or recursive loop..
Do you know for which method it goes wrong? Is it straight on the first propfind or does it happen in a later stage? I'll go and test this on my Mac as well, so far i've only tried it on Debian. I'm sure you are, but make sure your running it on a PHP version in the 5.2. range
Sorry, I didn't extract more info than that. The crash was so hard I wasn't keen on trying again...
I was running PHP 5.2.5 installed via MacPorts? (php5 @5.2.5_1+apache2+macosx+mysql5+sqlite).
works like a charm here, php-5.2.6 on gentoo linux, with a windows client.
evertpot, will there be a set of hooks which will let me do some actions on a delete/get/put or something? or do i have to write/extend my own driver for such things?
Hi Stephan,
To extend the webdav service with your own business logic, you have 2 choices. You can extend the Tree class, which basically gives you a method for every operation, or you can use the ObjectTree and create your own File and Directory classes.
http://code.google.com/p/sabredav/wiki/ObjectTree
An example of how this is done can be seen in the FS/ directory.
The latest version (0.3.118) fixes the segmentation faults I was having.
A comment on the instructions: "This is how the file should look like" refers to a file that has not previously been mentioned. Perhaps it should be clarified which file this is, where it should be located, etc.
I have assumed that this is the script that is going to respond to the request and that it can be located anywhere as long as the paths to the various directories and SabreDAV code are right, but it is not at all clear and the current wording is confusing (cut and pasted from a longer description perhaps?).
Apart from that the instructions on this page are simple and give you just enough to get you started.
Glad the segmentation fault was fixed.. I'll be updating the docs shortly as well, it does actually seem like part of the documenation is missing altogether..
Made some updates to this page based on the suggestions. If anyone if you guys (theo or stephan) are interested in getting access and help out, please let me know! Very happy with you guys finding my mistakes :)
I works perfectly. I tried to integrate it with my home made CMS and it works :) Unfortunately I had to change each require_once to get the right file. Did you think about any constant that would point to SabreDav? folder?
Hey Risto,
Adding a constant is a bit uncommon, it is generally recommended to make sure the library is in your 'include_path' instead. Once you got that, everything should work out of the box.
Evert
Suggested tools:
Wireshark for protocol debugging and the REST Client Firefox plugin for making custom HTTP requests.
Maybe fiddler proxy can help when debugging: some hints are on http://bit.ly/16htQ6