Saturday, August 09, 2008

LAPP on Ubuntu 8.04 (Hardy Heron)

To install LAPP (Apache, PostgreSQL, Perl on Linux)

At the prompt:

1) sudo apt-get install perl postgresql apache2
Say Y to download dependencies.
2) sudo su postgres
3) psql
> create table a(b integer);
> insert into a values(2);
> \password

Enter a new postgres database user password twice, say "qwe" (without quotes).
> quit
4) logout (of the postgres user only)
5) sudo vi /etc/postgresql/8.3/main/pg_hba.conf

Change all the "ident sameuser" in the last column of all (non-commented) lines to "md5".

6) sudo vi /etc/postgresql/8.3/main/postgresql.conf

Find the line:
#listen_address

Remove the hash from the start (de-comment it).
Change the address from 'localhost' to '*' (including quotes).

7) cd /usr/lib/cgi-bin
8) sudo vi c.cgi

#!/usr/bin/perl

use DBI;

print "Content-type: text\html\n\n";

my $dbh = DBI->connect('DBI:Pg:dbname=postgres;host=localhost','postgres','qwe')
or die "Couldn't connect to database: " . DBI->errstr;
my $sth = $dbh->prepare('SELECT * FROM a')
or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute()
or die "Couldn't execute statement: " . $sth->errstr;

while (@data = $sth->fetchrow_array()) {
print "$data[0]\n";
}
$dbh->disconnect();



9) sudo chmod +x c.cgi
10) Open firefox.
Try:
http://localhost/cgi-bin/c.cgi
You should see 2 on the screen.

This means LAPP (where the last P is Perl) is successfully installed.

No comments: