How to Install The PHP WebDAV Extension on Debian Squeeze

The PHP WebDAV extension enables users to access remote resources through WebDAV from PHP scripts without any difficulty. It is a quick and user-friendly C wrapper as compared to Neon library.

In this article, we have used a Debian Squeeze server. Make sure to install Apache2 and PHP5 on your system.


  • 1

    Installing The PHP WebDAV Extension

    You need to install some dependencies before installing the PHP WebDAV extension. The procedure is given below;

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

    Afterwards, you have to download and unpack the PHP WebDAV extension;

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

    Now, alter to the dav directory…

    cd dav/

    After that create the PHP WebDAV extension;

    ./configure --enable-dav
    make install

    To allow the extension, make the file /etc/php5/conf.d/dav.ini…

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

    Now, restart Apache:

    /etc/init.d/apache2 restart

  • 2

    Using The PHP WebDAV Extension

    The below script describes the procedure of using the PHP WebDAV extension;

    That example is quite easy to understand, and it also includes a README file in the PHP WebDAV source package that you have downloaded and has 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 pureftpd org

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

    This extension requires the Neon library and the related header wp-content/uploads.

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

× 5 = ten