Running Your Own Apache Server

     

Testing web applications or Apache modules might be as easy as testing the web applications in previous labs: configure Apache, run the server, and then run the tests. However, it can become a pain to make sure the Apache server is in a pristine state every time you want to run the tests. Apache-Test gives you the ability to start and stop a special Apache server to use for automated testing of Apache modules.


Note: Apache-Test is the distribution that contains Apache::Test and the related modules .

How do I do that?

Apache-Test needs a t/ directory for the server configuration, document root, and test files. Create the directories lib/ , t/ , and t/conf/ .

You also need a tiny program to start and stop the Apache server as well as to run the tests. Save the following as t/TEST :

 #!perl          use strict;          use Apache::TestRun;     Apache::TestRun->new->run(@ARGV); 

Suppose that you want to serve your photo album from the test server, a step that requires adding custom directives to Apache's configuration. Save the following as t/conf/extra.conf.in :


Note: You need to adjust the second argument of Alias to the full path of the directory you want to serve .
 Alias /pictures /home/anu/pictures          <Location /pictures>         Options +Indexes         Allow from all     </Location> 

It's also a good idea to tell Apache-Test where your Apache executable is. Do this by setting the APACHE_TEST_HTTPD environment variable in your shell:

 $  export APACHE_TEST_HTTPD=/usr/sbin/apache-perl  

Now, run TEST with the -start-httpd argument to start the demo server on the default Apache-Test port:


Note: If you use something besides the Bourne shell or a derivative, consult the manual for instructions on setting an environment variable .
 $  perl t/TEST -start-httpd  [warning] setting ulimit to allow core files     ulimit -c unlimited; /usr/bin/perl /home/anu/setup/t/TEST -start-httpd     /usr/sbin/apache-perl  -d /home/anu/setup/t -f         /home/anu/setup/t/conf/httpd.conf -D APACHE1 -D PERL_USEITHREADS     using Apache/1.3.33          waiting 60 seconds for server to start: .     waiting 60 seconds for server to start: ok (waited 0 secs)     server localhost:8529 started 

Congratulations ”you now have a web server serving your photo gallery!

There are a few things to note in the output, such as which Apache executable actually ran ( /usr/sbin/apache-perl ). The output also shows two options passed to the executable, the server root ( -d /home/anu/setup/t ) and the configuration file it used ( -f /home/anu/setup/t/conf/httpd.conf ). The output displays what version of Apache is in use, and then a few lines while the server starts. Finally, the last line of the output shows the host and port the daemon uses.

Navigate to the host and port with your browser. You should be able to browse the directory you specified in extra.conf.in , as Figure 7-3 shows.

Figure 7-3. Using a test Apache server

When you finish browsing and want to shut down the server, run TEST with the -stop-httpd argument:

 $  perl t/TEST -stop-httpd  [warning] setting ulimit to allow core files     ulimit -c unlimited; /usr/bin/perl /home/anu/setup/t/TEST -stop-httpd     [warning] server localhost:8529 shutdown 

You should no longer be able to access the web server with your browser.

What just happened ?

The TEST program puts together all of the pieces to execute and manage an Apache server and test suite that uses it. When you run TEST , it creates a configuration file that incorporates any additional files you provide, such as conf/extra.conf.in . TEST also creates a logging directory, t/logs/ by default, which holds the standard access_log and error_log files. After initialization, TEST launches an Apache server that listens on port 8529 by default.

TEST has many command-line options such as -verbose , which shows many more diagnostics. You can also use the -clean option to remove the slew of autogenerated files Apache-Test creates when it starts the server. Run TEST -help for a complete list of options.



Perl Testing. A Developer's Notebook
Perl Testing: A Developers Notebook
ISBN: 0596100922
EAN: 2147483647
Year: 2003
Pages: 107

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