CGI-Application-Framework
view release on metacpan or search on metacpan
lib/CGI/Application/Framework.pm view on Meta::CPAN
ServerName www.wepayu.com
SetEnv SITE_NAME DEBIT
# .... other per-host configuration goes here
</VirtualHost>
<VirtualHost *>
ServerName www.youpayus.com
SetEnv SITE_NAME CREDIT
# .... other per-host configuration goes here
</VirtualHost>
If you are mixing and matching databases, and you are running under a
persistent environment such as mod_perl, then you must make sure that
all of the schemas of all the databases you are using are identical as
far as C<Class::DBI> is concerned. In practice that means that the
following items must be the same across databases:
* table names
* column names
* which columns are primary keys
Other database details (such as how columns are indexed) may safely
differ from database to database.
=head1 DATABASE INSTALLATION
If you already have a database set up and you don't need to load the
example data for the Example applications to work, then you can skip
this section.
The Framework and its example programs support many databases. In
theory, any database that has a C<DBD::*> driver and a C<Class::DBI::*>
subclass module is supported. This distribution contains explicit
support for C<MySQL>, C<PostgreSQL> and C<SQLite>. There are instructions for
setting up each of these databases below.
If you like you can use more than one of these databases at the same
time. See L<"Using multiple database configurations"> below.
=head2 Database Installation - MySQL
This is how to create a MySQL database that works with the Example
applications.
In the C<framework/sql> directory, you will find a file called
C<caf_example.mysql>. First, this must be loaded into the MySQL
database. As the root user, type:
# cd framework/sql
# mysql < caf_example.mysql
This will create the "example" database and one table with a
few pre-populated rows, "users", and a bunch of other empty tables.
You will want the web application to be able to access the "example"
database as a non-root user, so you need to grant access to the
database. Do the following
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28 to server version: 4.0.21-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT ALL PRIVILEGES ON example.* TO
-> 'some_username'@'localhost' IDENTIFIED BY 'a_password';
Obviously, pick C<"some_username"> and C<"a_password"> that is appropriate
to your situation. If you are doing this for test purposes then
perhaps you can just use the username of your regular Unix user
account and set an empty password. Also, if you want the user to have
more privileges than just these you can modify this statement as
appropriate. See:
http://dev.mysql.com/doc/mysql/en/MySQL_Database_Administration.html
Item 5.6, "MySQL User Account Management", has information regarding
how to set up your grant statement.
Whatever you chose for some_username and a_password you must place these
into the configuration in your top-level framework.conf file:
<db_example>
dsn = DBI:mysql:database=example
username = rdice
password = seekrit
</db_example>
Note that other databases will require their own
<db_OTHER>...</db_OTHER> configuration blocks. More about this later.
For more information on the format of the 'dsn' parameter, consult the
DBD::mysql documentation:
http://search.cpan.org/~rudy/DBD-mysql/lib/DBD/mysql.pm
The caf_example.mysql file does not contain all of the data needed in
order to populate the database with seed data for all of the example
programs of the Framework. To load the rest of the data, do the
following:
# cd framework/sql/
# perl ./load_music_data.pl music_info.csv
This data is stored in a separate file and comes with its own loading
program, so that you can see more examples of how the CDBI modules is
used to accomplish real-life tasks. Inspect the contents of the
C<load_music_data.pl> file to see how it works.
=head2 Database Installation - PostgreSQL
This is how to create a PostgreSQL database that works with the Example
applications.
First you must create the example database.
Connect to the postgres database as the postgres user:
$ psql -U postgres template1
( run in 0.758 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )