Connecting Tech Pros Worldwide Forums | Help | Site Map

[Lighttpd] Writing to an external file?

Gilles Ganault
Guest
 
Posts: n/a
#1: Mar 24 '08
Hello

There's not much activity in the Lighttpd forum, so I figured maybe
some people here use this web server instead of Apache, and would know
the cause of the problem.

PHP scripts can successfully read/write to an SQLite file when it's
located either in Lighttpd's web directory (/usr/local/www/data/) or
in /tmp, but it fails writing when the file is located elsewhere (such
as /var).

I've checked file and directory ownership and access rights, as well
as /usr/local/etc/lighttpd.conf and Lighttpd's error log, to no avail.
I don't know where else to look for an explanation. Any idea?

Thank you.

PS : Here's the test code I use:

//BAD
$dbh = new PDO("sqlite:/var/test.sqlite");
//GOOD $dbh = new PDO("sqlite:test.sqlite");
//GOOD $dbh = new PDO("sqlite:/tmp/test.sqlite");

$time = time();
$current = date("Y-m-d H:i:s",$time);
$sql = "INSERT INTO mytable VALUES (NULL,'$current')";
print "$sql<hr>";
$dbh->exec($sql);

$sql = "SELECT * FROM mytable";
foreach($dbh->query($sql) as $row) {
print $row['name'] . "<p>\n";
}

$dbh = null;

NC
Guest
 
Posts: n/a
#2: Mar 24 '08

re: [Lighttpd] Writing to an external file?


On Mar 24, 4:32 am, Gilles Ganault <nos...@nospam.comwrote:
Quote:
>
PHP scripts can successfully read/write to an SQLite file when it's
located either in Lighttpd's web directory (/usr/local/www/data/) or
in /tmp, but it fails writing when the file is located elsewhere (such
as /var).
This is normal. HTTP servers usually run with very restrictive
permissions.
Giving an HTTP server write access to /var is asking for trouble...

Perhaps you should rethink what your problem really is. I am guessing
that
you want to protect your SQLite data file from downloading via HTTP.
In that
case, you should either place it outside the Web root into a directory
owned
by Lighttpd or deny HTTP access to the file or its containing
directory using
the url.access-deny directive available in Lighttpd:

http://trac.lighttpd.net/trac/wiki/Docs%3AModAccess

Cheers,
NC
Closed Thread