A Database-Driven Web Application in 18 Lines of Code
Maypole interacts directly with Apache through mod_perl. To work with Apache 2, a development library called libapreq2 needs to be fetched from the CPAN repository and installed into Perl. I downloaded libapreq2-2.04_03-dev.tar.gz from CPAN. Prior to installing the library, I upgraded the ExtUtils::XSBuilder module that ships with Perl. A single command, issued as root, suffices:
perl -MCPAN -e "install ExtUtils::XSBuilder"
If this is the first time the CPAN shell has executed, you'll be prompted to configure the local CPAN module. Be sure to select follow when asked about fetching prerequisite modules. With the module upgraded, I installed the libapreq2 library with the usual set of Perl module installation commands:
tar zxvf libapreq2-2.04_03-dev.tar.gz cd libapreq2-2.04-dev/ perl Makefile.PL make make test su make install <Ctrl-D>
The actual installation of Maypole starts by invoking the CPAN shell as root:
perl -MCPAN -e "shell"
As Maypole depends on a large collection of prerequisite CPAN modules, installation can take a while. Prior to actually asking the CPAN shell to install Maypole for you, issue the following commands to ensure that some of the more troublesome modules are dealt with:
cpan> install CGI::Untaint::date cpan> force install Class::DBI::mysql
I had to force the installation of Class::DBI::mysql as a number of tests failed, effectively aborting the automatic installation. By forcing the install, the broken tests are ignored, allowing the install to proceed. With the prerequisites dealt with, install Maypole with this CPAN command:
cpan> install Maypole
A series of automated interactions with the CPAN repository begin after this step. Keep an eye on what's going on, because at certain points, you have to respond to some self-explanatory prompts. When all was done and dusted, the most recent release of Maypole—2.04 at the time of this writing—was installed on my machine.
Returning to MySQL, I logged in as administrator and issued these commands to remove any default accounts:
mysql -u root -p mysql> use mysql; mysql> delete from user where User = ''; mysql> flush privileges;
I then created a new database, together with a user to act as owner of the data:
mysql> create database CLUB;
mysql> grant all on CLUB.* to manager identified
by 'passwordhere';
mysql> quit
These commands create the database, called CLUB, and add a user, called manager, to the database system. For the purposes of this article, this simple application manages data about an under-age soccer club. In addition to storing personal details about each player, the system maintains data on which players are in which squads, as well as any medical conditions players may have.
Here are the SQL files that I used to define the tables used within the CLUB database. The first file, create_player.sql, creates the player table:
create table player
(
id int not null auto_increment
primary key,
name varchar (64) not null,
date_of_birth date,
address varchar (255),
contact_tel_no varchar (64),
squad int,
medical_condition int
);
The second file, create_squad.sql, creates the initial list of squads:
create table squad
(
id int not null auto_increment primary key,
name varchar (32) not null
);
insert into squad (name) values ('--');
insert into squad (name) values ('Under 8');
insert into squad (name) values ('Under 9');
insert into squad (name) values ('Under 10');
insert into squad (name) values ('Under 11');
insert into squad (name) values ('Under 12');
The squad table is initialized to a reasonable set of default values. The third and final file, create_condition.sql, creates a list of possible medical conditions:
create table condition
(
id int not null auto_increment primary key,
name varchar (64) not null
);
insert into condition (name) values ('--');
insert into condition (name) values ('Asthma');
insert into condition (name) values ('Epilepsy');
As with the squad table, the condition table is initialized with some default data. The data item in the squad and condition tables is called name. The significance of this point will be returned to later in this article.
Use the SQL files to create the tables within the database:
mysql -u manager -p CLUB < create_player.sql mysql -u manager -p CLUB < create_squad.sql mysql -u manager -p CLUB < create_condition.sql
As can be guessed, the CLUB database maintains data on players. Players belong to a squad and may have a medical condition.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- Developer Poll
- Trying to Tame the Tablet
- Tech Tip: Really Simple HTTP Server with Python
- Deceptive Advertising and
23 min 44 sec ago - Let\'s declare that you have
24 min 41 sec ago - Alterations in Contest Due
25 min 47 sec ago - At a numbers mindset, your
26 min 58 sec ago - Do not get Just Almost any
30 min 27 sec ago - A fantastic rule-of-thumb to
31 min 50 sec ago - Keren mastah..
Penting,
1 hour 29 min ago - mini tablet compare
2 hours 48 min ago - Looking Good
6 hours 21 min ago - Hey God - You may not be
10 hours 35 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




Comments
Please help
I have tried to get the content of this article to work for three days now. I have finally got all the modules from CPAN installed. However when I try and use the App I get this message in the httpd error log:
failed to resolve handler `ClubDB':
and
Can't locate loadable object for module Apache::Constants
I installed Apache::Constants with
# perl -MCPAN -eshell
# install Apache::Constants
I have followed this article content and dont understant why it don't work.
Fights with Apache
I'm running SuSE 9.1 with Apache 2 and had a hard time fighting to get things working. The one thing which took me the longest time to figure out was the Apache::MVC module does a check to see if you're running Apache 1 or 2. If 2 it requires one set of libraries, if 1 then a different set.
They both require Apache::Request, but as far I've been able to determine, this is not available for Apache 2:
if (APACHE2) {
require Apache2;
...
} else { require Apache }
require Apache::Request;
I seem to have fixed the problem by putting the "require Apache::Request" line inside the else block.
I don't know Perl or the Apache modules enough to say if this is a bug in MVC, or if my system is grossly misconfigured. Regardless, Maypole is working for me now, but I'm continuing to research. Any ideas?
Thanks!
Can't compile libapreq2 either
Even though /sbin is in my path already. I'm on FC3 that was upgraded from FC2. I may try a clean new install in order to give this a whirl.
I couldn't get this tutorial
I couldn't get this tutorial to work until I made the following changes:
1. include /sbin in path when compiling libapreq2 module.
2. changed ClubDB.pm to have the following line:
ClubDB->setup( "dbi:mysql:CLUB", "manager", "passwordhere" );
instead of existing ClubDB->setup line.
Hope these tips help someone else save some hours.
Getting it to work
In addition to ElaineNormandy's suggestion which was key to getting this to work, I can offer these suggestions:
In ClubDB.pm since at line 9 we are in the ClubDB::Squad package definition, line 9 should be changed from "ClubDB::Player->untaint..." to "ClubDB::Squad->untaint...".
Be VERY carefull with your syntax in ClubDB.pm. For example, using curved braces, '(' and ')', instead of curly braces, '{' abd '}', after 'sub display_columns' causes the display of the associated table to be replaced by a message that the page can't be opened. The log ( logs/error.log) is minimally helpfull with this.
Be sure to restart Apache whenever ClubDB.pm is changed.
Paul Barry's article is thorough but does not walk you thru installing and setting up Apache and mod_perl, if you don't have them. This has to be done right to get the rest to work. Having the source code and all the resultant files from the build process (eg. apxs ) appears to be necessary to install libapreq2. My initial install of fc3 did not have these. It took a bit of poking around to get these required files in place.
All that said, I now have the tools in place to move some very usefull Interbase SQL databases to mysql and serve them up with browser technology to the various offices in our organization. Thanks to Paul Barry, Simon Cozens and Sebastion Riedel.
Getting it to work ... more
Paul Barry's article is thorough but does not walk you thru installing and setting up Apache and mod_perl, if you don't have them.
I initially had a version of the article that covered installing Apache/mod_perl from source. However, in discussions with LJ's editor, it was decided that the article would be more useful if I targetted a distribution's build of Apache/mod_perl, the thinking being that if a distribution issued a security fix, it could be applied to the system as a result of the distribution's updating system. The idea was that building from source would mean that the user would then be taking on responsibility for updating Apache/mod_perl when security patches were issued. It was felt that people are busy enough, so we stuck with a distribution's Apache/mod_perl package.
My initial install of fc3 did not have these. It took a bit of poking around to get these required files in place.
As the last step of Part 1, I state: "be sure to install the following packages from your chosen distribution: httpd, httpd-devel, mod_perl, mod_perl-devel, mysql (client and server) and Perl.". With these packages installed, APXS and the like are installed for you. I did this on FC3 with no real issues.
Interbase SQL
You may wish to try hooking Maypole up to Interbase and avoid the step of moving your data to MySQL. Maypole is database-independent. Worth checking out.
Thanks to Paul Barry, Simon Cozens and Sebastion Riedel.
Oh my ... all I did was write the article. The "Simons" did all the real work and they deserve all the credit.
Thanks for the comments on the article. Glad you found it useful.
Regards.
Paul.
Paul Barry
getting Maypole (this tutorial) to work
Unfortunately (or fortunately, depending on how you view things) Maypole and its API is constantly under development. The module is now at release 2.09, whereas my code worked under 2.04 and that was just a few short months ago. The best advice I can give web developers is to subscribe to the Mayole mailing list and to check any list archives. And -- yes -- getting Maypole to work is a challenge but, once it works, I think its worth the heartache.
Paul Barry
Paul Barry
Just the thing I've been pull
Just the thing I've been pulling my hair out over the last 20 mins. Thanks!