Installing The PHP WebDAV Extension On Debian Etch

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Mon, 2008-08-11 16:23. :: PHP

Installing The PHP WebDAV Extension On Debian Etch

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 08/05/2008

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
wget http://download.pureftpd.org/php-webdav/php-webdav-1.1.tar.gz
tar xvfz php-webdav-1.1.tar.gz

Then we change to the dav directory...

cd dav/

... and build the PHP WebDAV extension:

phpize
./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

extension=dav.so

... 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:

<?php
$res = webdav_connect('http://webdav.example.com/', '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);
webdav_close($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 http://php-webdav.pureftpd.org

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: http://www.webdav.org/neon/

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
system)

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

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

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

$res = webdav_connect('http://webdav.example.com/dav', '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);
webdav_close($res);

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

In order to establish a new connection, use:

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

Examples:

webdav_connect('http://webdav.example.org/dav/')
webdav_connect('http://webdav.example.org/dav/', 'myuser', 'mypassword')
webdav_connect('http://webdav.example.org/dav/', 'myuser', 'mypassword', 10)

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

webdav_close()
webdav_close($resource)

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

Examples:

webdav_connect('http://webdav.example.org/dav/');
$a = webdav_get('nice/object.txt');

=> fetch http://webdav.example.org/dav/nice/object.txt

webdav_connect('http://webdav.example.org/dav');
$a = webdav_get('/nice/object.txt');

=> also fetch http://webdav.example.org/dav/nice/object.txt

webdav_connect('http://webdav.example.org/dav');
$a = webdav_get('nice/object.txt');

=> WRONG : fetches http://webdav.example.org/davnice/object.txt

webdav_connect('http://webdav.example.org/dav/');
$a = webdav_get('/nice/object.txt');

=> WRONG : fetches http://webdav.example.org/dav//nice/object.txt

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

------------------------ 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
webdav_mkcol().

------------------------ 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
webdav_move().

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

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

<?php

require 'dav_stream.inc.php';

$fp = fopen('webdav://dav.example.com/dav/dir/file.txt', 'w');
fwrite($fp, "test\n");
fclose($fp);
$data = file_get_contents('webdav://dav.example.com/dav/dir/file.txt');
$st = stat('webdav://dav.example.com/dav/dir/file.txt');
copy('/tmp/xyz.txt', 'webdav://dav.example.com/dav/dir/xyz.txt');
unlink('webdav://dav.example.com/dav/dir/abc.txt');

?>

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

 

4 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.