There is a new version of this tutorial available for Debian 6 (Squeeze).

Installing The PHP WebDAV Extension On Debian Etch

Version 1.0
Author: Falko Timme

This article shows how you can install the PHP WebDAV extension for PHP5 on a Debian Etch system. The PHP WebDAV extension allows easy access to remote resources through the DAV protocol from PHP scripts.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm using a Debian Etch server here. I'm assuming that Apache2 and PHP5 are already installed and working.


2 Installing The PHP WebDAV Extension

Before we install the PHP WebDAV extension, we need to install a few dependencies as follows:

apt-get install php5-dev build-essential libneon26 libneon26-dev

Next we download and unpack the PHP WebDAV extension:

cd /tmp
tar xvfz php-webdav-1.1.tar.gz

Then we change to the dav directory...

cd dav/

... and build the PHP WebDAV extension:

./configure --enable-dav
make install

In order to enable the extension, we create the file /etc/php5/conf.d/dav.ini...

vi /etc/php5/conf.d/dav.ini

... and restart Apache:

/etc/init.d/apache2 restart

That's it!


3 Using The PHP WebDAV Extension

Here's a little PHP script that demonstrates how you can use the PHP WebDAV extension:

$res = webdav_connect('', 'webdavuser', 'webdavpassword');
webdav_put('/setup.txt', file_get_contents('/var/www/setup.txt'), $res);
$a = webdav_get('/setup.txt', $res);
echo $a;

webdav_unlink('/setup.txt', $res);
webdav_rename('/setup.txt', '/bla.txt', TRUE, $res);
webdav_copy('/bla.txt', '/setup.txt', TRUE, TRUE, $res);
webdav_unlink('/setup.txt', $res);

That example should be pretty self-explanatory, however there's also a README file in the PHP WebDAV source package that you've downloaded that contains a full function reference:

.:. PHP WebDAV extension .:.

------------------------ BLURB ------------------------

The PHP WebDAV extension allows easy access to remote resources through the
DAV protocol.

It is based upon the Neon reference library.

The PHP WebDAV extension home page is

Please report bugs and suggestions to j <at> pureftpd <dot> org

------------------------ INSTALLATION ------------------------

This extension requires the Neon library and the related header files.

Neon can be downloaded from:

Pre-built packages and ports are already available for most operating systems
and distributions.

In order to compile and install the PHP WebDAV extension, just follow the
standard PECL procedure :

$ phpize
$ ./configure --enable-dav
# make install

On OpenBSD systems, use
$ env AUTOCONF_VERSION=2.61 phpize

(replace 2.61 with any of the currently installed versions of autoconf on your

------------------------ BASIC EXAMPLE ------------------------

webdav_connect('', 'davuser', 'davpassword');
$a = webdav_get('/my/nice/object.txt');
webdav_put('/your/nice/thing.txt', $data);
webdav_rename('/dir/old_name', '/dir/new_name');
webdav_copy('/dir/orig_dir', '/dir/new_dir', TRUE);

------------------------ NAMED RESOURCE EXAMPLE ------------------------

$res = webdav_connect('', 'davuser', 'davpassword');
$a = webdav_get('/my/nice/object.txt', $res);
webdav_put('/your/nice/thing.txt', $data, $res);
webdav_unlink('/unwanted_resource.txt', $res);
webdav_rename('/dir/old_name', '/dir/new_name', $res);
webdav_copy('/dir/orig_dir', '/dir/new_dir', TRUE, $res);

------------------------ ESTABLISHING A CONNECTION ------------------------

In order to establish a new connection, use:

webdav_connect(string base_url [, string user [, string password
[, int timeout]]]


webdav_connect('', 'myuser', 'mypassword')
webdav_connect('', 'myuser', 'mypassword', 10)

Closing a session just requires a call to webdav_close() :


The base url is a string that will be concatened to URI parts of other
functions in order to get the full resource URL.


$a = webdav_get('nice/object.txt');

=> fetch

$a = webdav_get('/nice/object.txt');

=> also fetch

$a = webdav_get('nice/object.txt');

=> WRONG : fetches

$a = webdav_get('/nice/object.txt');

=> WRONG : fetches

As an alternative, the name webdav_open() can be used in place of

------------------------ FETCHING A RESOURCE ------------------------

In order to fetch a resource, use:
webdav_get(string uri [, resource session])

The function returns the content, or FALSE if an error occurred.

------------------------ STORING A RESOURCE ------------------------

Storing a resource is available through the webdav_put() function:
webdav_put(string uri, string data [, resource session])

------------------------ DELETING A RESOURCE ------------------------

webdav_delete() deletes a resource :
webdav_delete(string uri [, resource session])

As an alternative, the names webdav_unlink(), webdav_remove() and
webdav_rmdir() can be used in place of webdav_delete().

------------------------ CREATING A COLLECTION ------------------------

A collection (think about it as a subdirectory if you aren't familiar with
DAV) is created with the webdav_mkcol() function :

bool webdav_mkcol(string uri [, resource session])

As an alternative, the name webdav_mkdir() can be used in place of

------------------------ COPYING A RESOURCE ------------------------

If the server implements it, resources can be copied:

webdav_copy(string source_uri, string target_uri
[, bool overwrite [, bool recursive [, resource session]]])

By default, resources can be overwritten and they are recursively copied.

------------------------ MOVING/RENAMING A RESOURCE ------------------------

Resources can also be moved or renamed:

webdav_move(string source_uri, string target_uri
[, bool overwrite, [, resource session]])

As an alternative, the name webdav_rename() can be used in place of

------------------------------ PHP STREAM API ------------------------------

As an alternative to webdav_*() functions, the file can be
included in your projects so that DAV servers can be reached through standard
PHP calls, through webdav:// streams:


require '';

$fp = fopen('webdav://', 'w');
fwrite($fp, "test\n");
$data = file_get_contents('webdav://');
$st = stat('webdav://');
copy('/tmp/xyz.txt', 'webdav://');


This is a bit slower than native webdav_*() functions.


Share this page:

Suggested articles

0 Comment(s)

Add comment