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.
|Happy Birthday Linux||Aug 25, 2016|
|ContainerCon Vendors Offer Flexible Solutions for Managing All Your New Micro-VMs||Aug 24, 2016|
|Updates from LinuxCon and ContainerCon, Toronto, August 2016||Aug 23, 2016|
|NVMe over Fabrics Support Coming to the Linux 4.8 Kernel||Aug 22, 2016|
|What I Wish I’d Known When I Was an Embedded Linux Newbie||Aug 18, 2016|
|Pandas||Aug 17, 2016|
- Happy Birthday Linux
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- ContainerCon Vendors Offer Flexible Solutions for Managing All Your New Micro-VMs
- What I Wish I’d Known When I Was an Embedded Linux Newbie
- Updates from LinuxCon and ContainerCon, Toronto, August 2016
- NVMe over Fabrics Support Coming to the Linux 4.8 Kernel
- New Version of GParted
- Tor 0.2.8.6 Is Released
- All about printf
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide