I'm a Maypole newbie and just successfully got the BeerDB running on
FreeBSD with MySQL.  I wrote up the steps I took, and hope they are
useful to someone.

STEP BY STEP: 
Get Maypole 2.10 BeerDB working 
on FreeBSD 5.X
with perl 5.8.3, 
MySQL 4.1.10+
Apache 1.3 with mod_perl.

by John Krystynak (8/31/05)


1. UPDATE PORTS USING CVSUP.

   - Create a supfile like this:
   *default tag=.
   *default host=cvsup99.FreeBSD.org
   *default prefix=/usr
   *default base=/var/db
   *default release=cvs delete use-rel-suffix compress

   src-all

Then login as root and run

$ cvsup -g -L 2 supfile

This will likely take 20 minutes or more...


2. INSTALL APACHE AND MYSQL FROM THE PORTS IF YOU DON'T ALREADY HAVE
   THEM SET UP...

I'm skipping a lot of details on these installs...  see here for more:
http://www.freebsddiary.org/mysql.php
or do a google search on
"install mysql freebsd ports" or "install apache freebsd ports"

Here's the outline of the installs:
$ cd /usr/ports/www/apache
$ make install distclean

$ cd /usr/ports/databases/mysql41-server
$ make install

Also, there are a world of security concerns if you do this on a real
server!

Resources on securing Apache:
http://www.apachesecurity.net/about/links.html
FreeBSD:
http://www.onlamp.com/pub/a/bsd/2002/08/08/FreeBSD_Basics.html

Artur Maj has a couple of good articles on secure configuration of apache
and MySQL


3. INSTALL MOD_PERL ON APACHE FROM THE PORTS

$ cd /usr/ports/www/mod_perl
$ make install distclean

For gory details on building mod_perl, and adding SSL,
 see: http://perl.apache.org/docs/1.0/guide/install.html

Now you need to configure apache for mod_perl

$ emacs /usr/local/etc/apache/httpd.conf

Put the following in httpd.conf (change the all instances of the
server name and port to your own.)

################################
###### MOD_PERL CONFIGURATION
Listen 8282
<VirtualHost 192.168.126.129:8282>
    DocumentRoot /usr/local/htdocs
    ServerName 192.168.126.129:8282
</VirtualHost>

<Directory "/usr/local/htdocs">
    Options Indexes +FollowSymLinks
    AllowOverride None
    Allow from all
</Directory>

Alias /perl/ /usr/local/htdocs
PerlModule Apache::Registry
<Location /perl>
    SetHandler perl-script
    PerlHandler Apache::Registry
    Options ExecCGI
    PerlSendHeader On
    Allow from all
</Location>

####### MAYPOLE SECIONT
<Perl>
  # this is where BeerDB.pm lives
  use lib '/usr/local/htdocs/beerdb/lib';
</Perl>
  
<Location /beerdb>
    SetHandler perl-script
    PerlHandler BeerDB
</Location>
##################################

Restart apache:

$ apachectl restart

Give mod_perl a test run. For details on testing mod_perl see this article:
http://www.perl.com/pub/a/2002/03/22/modperl.html?page=2


4. INSTALL MAYPOLE FROM THE FREEBSD PORTS

$ cd /usr/ports/www/p5-Maypole
$ make install distclean

This will probably take 30 mins or more.  A ton
of perl modules will be built.  If it asks for optional
modules to install, just select them all.


5. YOU MAY NEED TO HAND INSTALL A FEW MORE MODULES.

$ cpan
cpan> install Class::DBI::mysql

I also needed to install Class::Accessor::Chained which handn't been
installed for some reason:

cpan> install Class::Accessor::Chained::Fast

Now your kit should be complete, as they say...


6. MOVE THE MAYPOLE TEMPLATES TO THE /USR/LOCAL/HTDOCS/BEERDB

$ cd /usr/local/htdocs
$ mkdir beerdb
$ cp -r /usr/local/share/Maypole/templates/ beerdb

This copied over the beer and factory template directories
Then I did a mkdir for the custom directory and left it empty:

$ mkdir custom

You might also want the maypole.css file in the basedir

$ cp /usr/local/share/Maypole/templates/maypole.css /usr/local/htdocs


7. COPY THE BEERDB.PM FILE TO LIB SINCE I HAD PUT THIS IN HTTPD.CONF ABOVE:

<Perl>
  # this is where BeerDB.pm lives
  use lib '/usr/local/htdocs/beerdb/lib';
</Perl>


$ cd /usr/local/htdocs/beerdb
$ mkdir lib
$ cp /usr/local/share/examples/Maypole/BeerDB.pm lib


8. MODIFY BEERDB.PM TO LOOK LIKE THIS FOR MYSQL

package BeerDB;
use Maypole::Application("-Debug");
use Class::DBI::Loader::Relationship;
use warnings;

my $user = "beer";
my $pass = "pass";

# Give it a name.
BeerDB->config->application_name('The Beer Database');

# Change this to the root of the web site for your maypole application.
BeerDB->config->uri_base( "http://192.168.126.129:8282/beerdb/"; );
BeerDB->config->template_root( "/usr/local/htdocs/beerdb/" );

# Specify the rows per page in search results, lists, etc : 10 is a
#  nice round number
BeerDB->config->rows_per_page(10);

# MySQL connection string
BeerDB->setup("dbi:mysql:beerdb", $user, $pass);

# Tell BeerDB about the database 
BeerDB->config->display_tables([qw[beer brewery pub style]]);
BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] );
BeerDB::Style->untaint_columns( printable => [qw/name notes/] );
BeerDB::Beer->untaint_columns(
    printable => [qw/abv name price notes url/],
    integer => [qw/style brewery score/],
    date =>[ qw/date/],
);
BeerDB::Pub->untaint_columns(printable => [qw/name notes url/]);

# Describe the relationships in the database
BeerDB->config->{loader}->relationship($_) for (
    "a brewery produces beers",
    "a style defines beers",
    "a pub has beers on handpumps");


1;


9. CREATE THE DATABASE IN MYSQL

Add the beer new user account
$ mysql -u root -p mysql
mysql> GRANT ALL PRIVILEGES ON beerdb.* TO 'beer'@'localhost'
 -> IDENTIFIED BY 'pass' WITH GRANT OPTION;
mysql> quit;

Put the following in beerdb.sql:

---------------------------------------------------------
--
-- MySQL script to load the beerdb schema and put in some sample data
--

drop database beerdb;
create database if not exists beerdb;
use beerdb;

create table brewery (
    id int unsigned NOT NULL AUTO_INCREMENT,
    name varchar(30),
    url varchar(50),
    notes text,
    PRIMARY KEY(id)
);

create table beer (
    id int unsigned NOT NULL AUTO_INCREMENT,
    brewery int unsigned,
    style int unsigned,
    name varchar(30),
    PRIMARY KEY(id)
);

create table handpump (
    id int unsigned NOT NULL AUTO_INCREMENT,
    beer int unsigned,
    pub int unsigned,
    PRIMARY KEY(id)
);

create table pub (
    id int unsigned NOT NULL AUTO_INCREMENT,
    name varchar(60),
    url varchar(255),
    notes text,
    PRIMARY KEY(id)
);

create table style (
    id int unsigned NOT NULL AUTO_INCREMENT,
    name varchar(60),
    notes text,
    PRIMARY KEY(id)
);

-- Put in some sample data - which I found on this blog entry:
--   http://laughingmeme.org/archives/001898.html

insert into brewery (name,url) values
('Elysian Brewing Company', 'http://www.elysianbrewing.com/');
insert into pub (name,url,notes) values ('Tangletown','','2106 N 55th St');
insert into style (name) values ('IPA');
insert into style (name) values ('Pilsner');
insert into beer (name, brewery, style) values ('Elysian Fields', 1, 1);
insert into beer (name, brewery, style) values ('Zephyrus', 1, 2);
insert into handpump (beer,pub) values (1,1);
insert into handpump (beer,pub) values (2,1);

---------------------------------------------------------

Then load the script into mysql:
$ mysql -u beer -p beerdb < beerdb.sql



10. TRY OUT THE RESULT IN A BROWSER:

lynx http://192.168.126.129:8282/beerdb/

If it doesn't work, you need to look at your httpd-error.log

$ tail -f /var/log/httpd-error.log

Good, you may be done... or probably not.

Modules may still be missing, permissions may be wrong, the template
files are a good source of potential issues... etc.

Sometimes apache needs to be restarted to clear out old config
settings from BeerDB.pm.  So if it can't find the right templates,
check the paths in BeerDB.pm.  If they are right, try restarting apache.




-- 
Check out my AdWords and Overture blog:
http://gotads.blogspot.com


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users

Reply via email to