Help-Site Computer Manuals
  Algorithms & Data Structures   Programming Languages   Revision Control
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

Introduction to Apache2::ASP

Apache2::ASP::Manual::Intro - Introduction to Apache2::ASP


Apache2::ASP::Manual::Intro - Introduction to Apache2::ASP




      <%= "Hello, World!" %>



        for( 1...10 ) {

          $Response->Write( "Hello from ASP ($_)<br>" );






Apache2::ASP is a new implementation of the ASP web programming for the mod_perl2 environment. Its aim is high performance, stability, scalability and ease of use.

If you have used the Apache::ASP manpage already then you are already familiar with the basic idea of ASP under Apache.


What is Apache2::ASP?

Apache2::ASP is a web programming environment that helps simplify web programming with Perl under mod_perl2. Apache2::ASP allows you to easily embed Perl into web pages using the ``<%'' and ``%>'' tags that are familiar to anyone who has used ASP or JSP in the past.

What does Apache2::ASP offer?

Apache2::ASP offers programmers the ability to program web pages without spending time on details like session state management, file uploads or template systems.


Like other ASP web programming environments, Apache2::ASP provides the following global objects:


Represents the incoming HTTP request. Has methods to handle form data, file uploads, read cookies, etc.

Learn more by reading the the Apache2::ASP::Request manpage documentation.


The same as $Request->Form, it is a hashref of all incoming form and querystring values.


Represents the outbound HTTP communication to the client. Has methods to send content, redirect, set cookies, etc.

Learn more by reading the the Apache2::ASP::Response manpage documentation.


Represents data that should persist beyond the lifetime of a single request. For example, the user's logged in state, user id, etc.

The contents of the $Session object are stored within an SQL database.

Learn more by reading the the Apache2::ASP::Session manpage documentation.


Represents the webserver itself and offers several utility methods that don't fit anywhere else.

Learn more by reading the the Apache2::ASP::Server manpage documentation.


Represents data that should be shared and persisted throughout the entire web application. For example, database connection strings, the number of active users, etc.

The contents of the $Application object are stored within an SQL database.

Learn more by reading the the Apache2::ASP::Application manpage documentation.


Encapsulates all the configuration information for your web application.

Learn more by reading the the Apache2::ASP::Config manpage documentation.



  % perl -MCPAN -e shell

  cpan> install Apache2::ASP


  cpan> quit

Then you're done and can skip ahead to Directory Structure.

Command Line

If (for whatever reason) the CPAN installation doesn't work for you, simply extract Apache2-ASP-xxx.tar.gz, then cd to that directory and run the following commands:

  % su non-root-user

  % perl Makefile.PL

  % make

  % make test

  % exit

  % make install

Because Apache2::ASP makes use of the the Apache::Test manpage framework, you cannot run the tests as root unless the ``nobody'' user can create files in the current directory. That's life.

Directory Structure

You might be wondering, ``What does the directory structure for an Apache2::ASP website look like?''

Well, it looks like this:


  |-- conf (+r)

  |   |-- apache2-asp-config.xml

  |   `-- httpd.conf

  |-- etc (+r)

  |   |

  |   `-- Any other files needed by the site.

  |-- MEDIA (+rw)

  |-- PAGE_CACHE (+rw) - Compiled ASP scripts will be placed here automatically.

  |-- tmp (+rw)

  |   |

  |   `-- SQLite database files go here.

  |-- lib (+r)

  |   |

  |   `-- your *.pm modules go here (i.e. Class::DBI or DBIx::Class modules, but *not* Handlers).

  |--handlers (+r)

  |  |

  |  `

  `-- www (+r)


      `-- index.asp


You need to add the following to your httpd.conf


  # Needed for CGI::Apache2::Wrapper to work properly:

  LoadModule apreq_module    /usr/local/apache2/modules/


  # Set the directory index:

  DirectoryIndex index.asp


  # Set this variable:

  PerlSetEnv APACHE2_ASP_APPLICATION_ROOT /path/to/your/web/application


  # Load up some important modules:

  PerlModule Apache2::ASP

  PerlModule Apache2::ASP::PostConfigHandler

  PerlPostConfigHandler Apache2::ASP::PostConfigHandler


  # Configuration for MediaManager:

  PerlModule        Apache2::ASP::TransHandler

  PerlTransHandler  Apache2::ASP::TransHandler


  # All *.asp files are handled by Apache2::ASP

  <Files ~ (\.asp$)>

    SetHandler  perl-script

    PerlHandler Apache2::ASP



  # Prevent anyone from getting your

  <Files ~ (\.pm$)>

    Order allow,deny

    Deny from all



  # All requests to /handlers/* will be handled by their respective handler:

  <Location /handlers>

    SetHandler  perl-script

    PerlHandler Apache2::ASP



  # Main website:

  <VirtualHost *:80>


    DocumentRoot  /path/to/your/web/application/htdocs


XML Config File

Then create a directory at /path/to/your/website/PAGE_CACHE at the root of your application. The Apache server process should be able to read and write in this directory.

Then, in /path/to/your/website/conf add the file apache2-asp-config.xml. It will contain data like this:

  <?xml version="1.0" ?>



      <!-- This should be a regex that matches your site. -->































    <!-- You can specify more web_application elements below. -->



Although performance is poor on Windows, it works fine for testing or developing. I would not recommend running a production web application on Windows however.


Then, in your database, create a table with the following structure:

  CREATE TABLE asp_sessions (

    session_id CHAR(32) PRIMARY KEY NOT NULL,

    session_data BLOB,

    created_on DATETIME,

    modified_on DATETIME


Also create a table with the following structure:

  CREATE TABLE asp_applications (

    application_id VARCHAR(100) PRIMARY KEY NOT NULL,

    application_data BLOB


Simply (re)start Apache and installation is complete. Now you need some ASP scripts.

If your website is in /var/www/html then create a file ``index.asp'' in /var/www/html.

Your index.asp could contain something like the following:



      <%= "Hello, World!" %>



        for( 1...10 ) {

          $Response->Write( "Hello from ASP ($_)<br>" );





Then point your browser to and see what you get.

If everything was configured correctly, the output would look like:

  Hello, World! 

  Hello from ASP (1)

  Hello from ASP (2)

  Hello from ASP (3)

  Hello from ASP (4)

  Hello from ASP (5)

  Hello from ASP (6)

  Hello from ASP (7)

  Hello from ASP (8)

  Hello from ASP (9)

  Hello from ASP (10)

If you get an error instead, check out your error log to find out why.


It's possible that some bugs have found their way into this release.

Use RT to submit bug reports.


Please visit the Apache2::ASP homepage at to see examples of Apache2::ASP in action.


John Drago


Copyright 2007 John Drago, All rights reserved.

This software is free software. It may be used and distributed under the same terms as Perl itself.