LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-10-2010, 09:05 PM   #1
glibdud
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
Apache, Perl, and SQLite - so close!


Hi folks. I'm setting up a small database with a simple front end of HTML forms, and CGI written in Perl to process it. Most of it seems to be working, but I'm struggling with what appears to be a permissions issue on the database file, but I can't figure it out.

I'll preface this by saying I'm new to both HTML forms and CGI, though I've been working with Perl+SQLite for a while now, and I haven't run into this sort of problem before.

I'm not going to go into a ton of detail on my setup just yet, hoping someone can spot a noob error before I write a novel. But if that's not the case, I'll add as much detail as I can.

Most of this setup seems to be working. I've verified that my Perl CGI script is receiving the data posted by the HTML form. I'm able to use Server Side Includes to insert some dynamic data into a page. I've successfully pulled data out of my SQLite database and displayed it. The problem comes up when I try to write to the database from a script... it fails. The first time I tried, I got this message in my Apache errorlog:
Code:
[Tue Aug 10 19:58:47 2010] [error] [client x.x.x.x] DBD::SQLite::db do failed: attempt to write a readonly database at /usr/lib/cgi-bin/action_add.cgi line 46., referer: http://x.x.x.x/rw/add.shtml
...which was straightforward enough, as I hadn't set the group write permission. I set that up, tried again, but no luck:
Code:
[Tue Aug 10 20:00:14 2010] [error] [client x.x.x.x] DBD::SQLite::db do failed: unable to open database file at /usr/lib/cgi-bin/action_add.cgi line 46., referer: http://x.x.x.x/rw/add.shtml
All files involved are definitely readable by the webserver. I know it sees the database, as it can read from it just fine. I even tried setting permissions to 777... no luck.

So... are there any glaring oversights here? Or do I need to describe my setup a bit more thoroughly?

Thanks.
 
Old 08-10-2010, 09:31 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
are every folder from / down to /usr/lib/cgi-bin/ +rx for everyone?
 
Old 08-11-2010, 07:13 AM   #3
glibdud
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by AlucardZero View Post
are every folder from / down to /usr/lib/cgi-bin/ +rx for everyone?
Yes, /usr, /usr/lib, and /usr/lib/cgi-bin are all 755.
 
Old 08-11-2010, 07:24 AM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
What's in action_add.cgi lines 40-50?
 
Old 08-11-2010, 07:53 AM   #5
glibdud
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Here's the block it's in... line 46 is the do statement.

Code:
if( grep(/^$formdata{name}$/, @namelist) ) {
   print "<H3>Already exists.</H3>\n";
   print "<P>\"$formdata{name}\" already exists in the database.\n";
} else {
   $db->do("INSERT INTO Names VALUES(\"$formdata{name}\")");
   $db->commit;
   print "<H3>Success.</H3>\n";
   print "<P>\"$formdata{name}\" added to database.\n";
}
I've tried replacing the do with a prepare and execute... same error happens on the execute statement. Also played around with single-quotes vs. double-quotes, and inserting a static value instead of a variable, just to eliminate any code weirdness. I'm reasonably certain it's a setup issue.
 
Old 08-11-2010, 08:10 AM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

I wrote a CGI writing to sqlite some time ago, and I think I had to give the web server write permission on the directory where the database file was. Having write permission on the file only didn't work for some reason.
 
1 members found this post helpful.
Old 08-11-2010, 08:16 AM   #7
glibdud
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Guttorm View Post
Hi

I wrote a CGI writing to sqlite some time ago, and I think I had to give the web server write permission on the directory where the database file was. Having write permission on the file only didn't work for some reason.
Aha! That did it, thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Easy installation of LASP (Linux, Apache, SQLite and PHP) on Ubuntu LXer Syndicated Linux News 0 09-12-2009 12:51 AM
PHP 5.1.2 / Apache 2.2 / SQLite install error on FC4 Ravo Linux - Software 3 03-09-2006 03:16 PM
Perl: Wait for ssh connection to close kenneho Programming 9 10-29-2005 09:19 AM
Perl Sqlite DBI $sth->rows The Jesus Programming 0 10-21-2003 11:35 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration