What Youll Need

only for RuBoard - do not distribute or recompile

What You ll Need

This section describes the primary tools we ll use for building dynamic Web sites and why we re using them. It also discusses the possibilities for adapting the principles and techniques presented here if you prefer to use different tools.

If you need to obtain any of the components discussed in this section, you can find instructions in Appendix A, Obtaining Software.

Software Requirements

Given the purpose of building database-backed Web sites, we ll need three major components: a Web server, a database management system, and some glue a programming language to connect the Web server to the database so that they can talk to each other. Let s look at each of these components a little more closely:

  • Web server. For the Web server component, we ll use Apache, an extensible, high-performance server that also happens to be more popular than any other on the Internet.

  • Database management system. The database is MySQL, a freely available system that is easy to use and administer, and that has good performance. The database engine itself is extremely fast, and the overhead for setting up connections to it is very low. That s an important factor in constructing a responsive Web site; lower overhead translates directly into the capability to handle a higher hit rate and lower hardware requirements. These characteristics make MySQL an excellent choice as a Web development database, which accounts for much of its popularity. (Note that you don t necessarily need to install a MySQL server you just need access to one. You can write your scripts to connect to databases that are hosted on somebody else s machine, if they ve set up access privileges for you.)

  • Programming language. There are interfaces to MySQL for many languages, so developers have a variety of choices for connecting MySQL to the Web. The glue we ll use to connect the two is Perl, the predominant scripting language on the Web. Perl is popular largely due to its power and versatility, its excellent support for text manipulation, and the number of third-party modules available for it that extend its native capabilities. Two of these are of particular significance for our purposes. The CGI.pm module provides an interface to the Web, making it easy to generate Web pages and to process input gathered from site visitors. The DBI module provides an interface to MySQL and makes it easy to issue database queries from within Perl scripts. An additional integration tool we ll use is mod_perl. This is actually an Apache module, not a Perl module. However, mod_perl makes it possible to embed the Perl interpreter into Apache so that Perl can be executed directly as part of the Web server rather than as a process external to it. This increases performance by eliminating the expense of starting up an additional process each time the server needs to run a Perl script.

In conjunction with the primary components just listed, we ll use other existing packages or applications on occasion rather than writing our own. (One part of effective Web site construction is knowing when to build on the work of others and avoid doing the work yourself.) These packages are secondary tools that will be described further when it comes time to use them.

Many books already address Web site construction and database integration with the Web. There are also plenty of books on Perl programming, including one specifically covering the DBI module, that show how to access databases from Perl. Why one more, and why focus on MySQL?

The answer is actually quite simple. Despite its usefulness, the combination of MySQL and Perl for Web programming has been strangely overlooked. In the Open Source community, for instance, the two most popular Web scripting languages are Perl and PHP. But although Perl has been around longer than PHP, for some reason most MySQL Web coverage has focused on the PHP interface to MySQL. There is relatively little treatment of Perl MySQL applications, even though Perl is just as important. Go into any bookstore and have a look at the many Perl books. Most of them touch on the Web and databases either not at all or devote only a few paragraphs or pages to the topic. Of these, the number that address MySQL is fewer yet. This is unfortunate, because one of MySQL s strengths is its applicability to Web programming.

The lack of coverage of Perl in comparison to PHP is surprising, given Perl s longevity and popularity. Although PHP is often held to be easier to learn than Perl (and thus a better choice for beginners or less-experienced Web developers), Perl has several important advantages: superior text-processing facilities, a richer set of data structures, and a more mature object-processing model. In addition, due to Perl s longer tenure, many more packages that provide capabilities beyond what is built in to the language have been written for Perl, so it has better support for some key technologies such as XML processing.

Perl and MySQL make a strong combination for Web programming, and their use continues to increase. It is important for developers to have a source of information on this topic to which they can turn for assistance. That s what this book gives you.

Hardware and Operating System Requirements

In addition to the Web development components just discussed (Apache, MySQL, Perl), you also need some hardware and an operating system on which to run the site. I m going to assume that you have access to some kind of UNIX box that is connected to the Internet.[1] You may even find you already have the software you need. Many distributions of UNIX these days include Apache, MySQL, and Perl, and allow you to install them either when you re installing the operating system or later after your system is up and running.

[1] Unless indicated otherwise, I generally use the term UNIX to mean Linux and UNIX. As it happens, all our software runs on most of the free versions of Linux or BSD UNIX, as well as on many commercial versions of UNIX. If there is any question, check the installation instructions for each component to see whether there are any issues with the operating system you plan to use.

The system you use can be run by yourself or your organization, or a system to which you have access by means of an account with an Internet service provider (ISP). If you have an ISP account (and therefore don t have full control over your machine), you need to pay special attention to some issues. These issues are covered in Chapter 9, Security and Privacy Issues. Here, too, you may find the software is installed already. Many ISPs provide database and scripting support as part of their Web account services.

If you have yet to acquire the hardware for your system and are still in the evaluation stage, you may be wondering whether you need to make a huge investment to construct a responsive site that has good performance. You probably don t. Many people find that servers running on relatively inexpensive machines are perfectly sufficient. Many sites are based on the combination of a PC and one of the freely available versions of UNIX or Linux. Indeed, several companies have discovered that such systems are sufficiently popular and it is possible to base a viable business venture on selling them as Internet servers and providing support for them. It s not a bad idea to contact some of these companies to see what they have to offer. They will be happy to help you select equipment. If you plan to handle millions of hits a day, however, you need equipment that is more high-powered than what most of us use; but they can help you with that, too.

Adapting This Book for Other Systems

If you are interested in using the material presented in this book but would like to develop and run your Web site on some other kind of system or use software other than what is used here this section provides some guidelines and some estimation of the likelihood that you will be successful.

One choice you can make is to run your Web site under Windows rather than under UNIX. Apache, MySQL, and Perl all run under Windows (as do CGI.pm, DBI, and mod_perl).

You should be able to substitute a different database for MySQL. The architecture of the Perl DBI module is designed to make it easy to port an application written for one database so that you can use it with another. DBI does this by providing an abstract interface to database engines. This gives you some leverage should you decide to use (or should a client request that you use) a database other than MySQL. Note that in this book we will use some MySQL-specific constructs; any applications that use these will need some rewriting.

There are means other than mod_perl for improving the performance of Perl scripts run from your Web server. Some alternatives are FastCGI or (if you want to consider commercial software) VelociGen.

You may be able to use another Web server, as long as it has the capability to run Perl scripts. Xitami runs under both UNIX and Windows, for example, and has support for Perl CGI programs.There is no support for embedding the Perl interpreter into Xitami, however. This means you will sacrifice some performance because the server needs to instantiate a separate process to run Perl scripts.

The most difficult part of the example software suite to replace would be the programming language.Virtually every script in this book is written in Perl, so if you want to use another language, you ll have a lot of work to do.

What You Should Know (Reader Requirements)

It s best if you already have some basic familiarity with most of the tools we use throughout this book, because this book is not intended as a beginner s guide. The book won t teach you all the basics of writing SQL queries or Perl programs. If you don t know anything about SQL, HTML, or programming, you ll probably have some difficulty. Despite that warning, however, you should be able to make productive use of this book if you have a reasonable amount of determination. If you re hoping to find out how to put together a more interesting or useful Web site, this book can teach you even if you don t know much beyond writing a static HTML page.

If you do happen to be a beginner, here are some words of advice:

  • Be sure to read Chapter 2, Getting Connected Putting Your Database on the Web. You ll find that chapter of particular importance as a starting point. More experienced readers who are already running a Web site may be able to pass over some or all of the material presented there.

  • Supplement your reading here with other material. See Appendix B, References and Further Reading.

  • Join some mailing lists, such as those for MySQL and DBI.

only for RuBoard - do not distribute or recompile


MySQL and Perl for the Web
MySQL and Perl for the Web
ISBN: 0735710546
EAN: 2147483647
Year: 2005
Pages: 77
Authors: Paul DuBois

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net