HPlogo Configuring and Managing MPE/iX Internet Services > Chapter 9 Apache for MPE/iX

Major Components

MPE documents

Complete PDF
Table of Contents
Index

E0802 Edition 6
E0701 Edition 5 ♥
E0400 Edition 4

After installing the Apache product, the following major files and directories will be created on the system under the directory /APACHE/VUUFF/:
HTTPD

The Apache web server program. "HTTP" stands for the protocol used between the client browser and the Apache web server. "D" stands for daemon, a system program which automatically handles certain system operations. The HTTPD web server program intercepts an incoming request from the browser, interprets and handles the request, then delivers output back to the client.

The HTTPD program file is linked with Privilege Mode (PM) capability. Because HTTPD is a Privilege Mode program, it must run under an MPE/iX account and group which both have PM capability. PM is necessary for Apache to use port numbers less than 1024 (privileged ports). By default, Apache uses port 80.

JHTTPD.sample

The sample file for creating the Apache start-up job. JHTTPD is streamed to run the Apache web server as a standalone process. This file specifies the system timezone and the location of the global Apache configuration file, httpd.conf.

bin/

The directory for Apache utility scripts and programs contributed by the Apache Software Foundation. Included in this directory are the htpasswd utility, used in Basic Authentication, and the apxs utility, for creating DSOs.

cgi-bin/

The directory for CGI scripts. CGI scripts are executed by Apache on behalf of its clients. Sample CGI scripts are distributed as part of the product.

conf/

Location of the Apache run-time configuration files. The configuration files tell the HTTPD server program where to find files, which files and directories can be accessed and who can access them, the location of CGI programs and much more. Apache is highly configurable and Apache's config files determine how the web server will behave.

htdocs/

The htdocs directory contains the public documents, images, and data to be served to clients. The htdocs directory and the directories below it are available to anyone accessing your web server.

htdocs/manual/

This directory contains a full, on-line manual set (HTML format) for Apache. These files describe the entire Apache feature set and the syntax definitions for configuring these features. Access to the manual documents is specified with the URL, http://yourserver.com/manual/index.html, where "yourserver.com" is the name of your HP e3000.

icons/

This directory contains images used by Apache.

include/

This directory contains the Apache C header files required for compiling DSOs.

libexec/

By convention, this is the location for DSO modules.

logs/

The logs directory contains log files including web server accesses (access_log) and errors (error_log).

man/

Location of the man pages for the Apache utilities in bin/. To make these pages viewable with the man command, add the man/ directory to your MANPATH environment variable:


  shell/iX>export MANPATH="/APACHE/PUB/man:$MANPATH"
  shell/iX>man apxs
  shell/iX>man htpasswd

proxy/

Directory where Apache caches documents when it is operating as a proxy server.

public_html/

The home directory for MGR.APACHE. It is accessed by http://yourserver.com/~MGR.APACHE/.

Preparing HP e3000 for Network Access


Before an HP e3000 can act as a web server, it must be available for network access via TCP/IP:
  • Configure TCP/IP on the system.

  • Have a domain name associated with the system's IP address.

Apache communicates on the network using the HTTP Hypertext Transfer Protocol which, in turn, uses TCP/IP. NS Transport (the TCP/IP transport subsystem) is configured on the HP e3000 using NMMGR. In NMMGR, configure the system's IP address and subnet mask in screen NEXTPORT.NI.NIname.PROTOCOL.IP. TCP should be configured with the recommended values shown in Table 9-1 "Recommended TCP/IP Values", using the NMMGR screen NEXTPORT.GPROT.TCP. Information on TCP/IP parameters is available in the NS 3000/iX NMMGR Screens Reference Manual from http://docs.hp.com/mpeix/all/index.html.

Table 9-1 Recommended TCP/IP Values

TCP/IP Parameter

Value
Maximum number of connections20,000
Retransmission Interval Lower Bound1 second
Maximum time to wait for remote response120 seconds
Initial Retransmission Interval2 seconds
Maximum Retransmissions per Packet6
Connection Assurance Interval120 seconds
Maximum Connection Assurance Retransmissions2

After completing the system's TCP/IP configuration, run :NETCONTROL START from the CI command line and verify that it ran successfully. Also verify that the system can respond over the network by running ping either from an HP e3000 or another system:

  :run ping.net.sys;info="15.99.200.390"

  64 byte(s) from $0F0DC0CF : icmp seq = 11, time = 2 ms
  64 byte(s) from $0F0DC0CF : icmp seq = 12, time = 3 ms
  64 byte(s) from $0F0DC0CF : icmp seq = 13, time = 2 ms
  < CONTROL-y >


  C:\>ping yourserver.com
  Pinging yourserver.com [15.99.200.390] with 32 bytes of data
  Reply from 15.99.200.390: bytes=32 time<10ms TTL=199
  Reply from 15.99.200.390: bytes=32 time<10ms TTL=199
  Reply from 15.99.200.390: bytes=32 time<10ms TTL=199

You will also want a domain name. This is a unique identifier such as "yourserver.abc.com" which is used (instead of the IP address) to direct requests from a browser to a web server. Request a domain name from the administrator of the Domain Name Server (DNS) on your network.

Configure the web server with one or more Domain Name Servers (DNS). These DNS servers will resolve the system's name into its IP address. To configure, edit RESLVCNF.NET.SYS or edit /etc/resolv.conf (which links to RESLVCNF.NET.SYS):
  • Add one or more nameserver lines. Each line should contain the IP address of a valid DNS.

  • Add one domain line that contains the DNS domain name for the domain to which your web server belongs. This domain name should not include the web server's hostname (:NMMGR node name).

  • The DNS server listed on each nameserver line must contain both a valid "A" record and "PTR" record. The content of these records must agree with the actual hostname of the web server and the actual domain name in RESLVCNF.NET.SYS.

For example, if the fully qualified domain name of the web server is yourserver.abc.com:

  shell/iX> uname -n
  YOURSERVER

  shell/iX > cat /etc/resolv.conf
  #domain <domain>
  #nameserver <primary server's IP address>
  #nameserver <secondary server's IP address>
  #
  #
  domain abc.com
  nameserver 25.33.100.134
  nameserver 25.33.125.172

Configure Apache


The /APACHE/VUUFF/conf directory contains the Apache configuration files. You will need your own copies of these under the /APACHE/PUB/conf directory. The .sample files are derived from the .default files with modifications for MPE/iX. The installation job sets up links to the /APACHE/VUUFF/conf directory so the following copy commands will get the new versions. Make sure to logon as MGR.APACHE before beginning configuration:

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS -L

  shell/iX> cd /APACHE/PUB/conf
  shell/iX> cp mime.types.sample mime.types
  shell/iX> cp magic.sample magic
  shell/iX> cp httpd.conf.sample conf
  shell/iX> cp access.conf.sample access.conf  (optional)
  shell/iX> cp srm.conf.sample srm.conf        (optional)

The access.conf.sample file and the srm.conf.sample file need not be copied. These files were used in earlier versions of Apache but their content is now included in the httpd.conf file. However, if these files exist, Apache will read and process them after processing the httpd.conf file.

Edit httpd.conf


Apache reads the httpd.conf file and the mime.types file at startup (and access.conf and srm.conf if they exist). These configuration files determine how Apache behaves. It is usually not necessary to modify the mime.types file. Edit the httpd.conf file for your own server, you may also wish to change other default values in httpd.conf.

The Httpd.conf is a bytestream file which can be edited on the HP e3000 using "vi" or can be modified from a PC if Samba is installed on the HP e3000.

  shell/iX> cd /APACHE/PUB/conf
  shell/iX> vi httpd.conf

  1. Modify the following httpd.conf directives by replacing "yourserver.com" with your own server name:

    • ServerAdmin MGR.APACHE@yourserver.com

    • ServerName yourserver.com

    All lines beginning with # are comments and are ignored by the HTTPD program file. Changes to the global configuration files do not take effect until the web server is started or restarted via kill -HUP.

    These are the only changes that need to be made to start up the web server. For information about other configuration directives, visit the online Apache documentation at http://www.apache.org/docs.

  2. Verify the configuration file. It is a good idea to verify your configuration files before trying to start the web server. This verification is for syntax checking only.

    
      shell/iX> /APACHE/PUB/HTTPD -t
      Syntax OK
    
    

Setup the JHTTPD Job Stream File


The JHTTPD.sample file should be copied to JHTTPD in PUB.APACHE and modified as needed. The /APACHE/VUUFF directory contains the new JHTTPD.sample file. The Apache installation job sets up a link to /APACHE/VUUFF so that the copy command gets the new version.

  shell/iX> cd /APACHE/PUB
  shell/iX> cp JHTTPD.sample JHTTPD
  shell/iX> cat JHTTPD
  !job jhttpd,www.apache,pub;outclass=,2
  !setvar TZ 'PST8PDT'
  !xeq sh.hpbin.sys "-c 'umask 007;./HTTPD -f conf/httpd.conf'"
  !eoj

The JHTTPD Job Stream File is used to run the HTTPD web server program in standalone mode within your local timezone. The timezone variable, TZ, should be set to the local timezone (for example, EST5EDT for Eastern Daylight Time, PST8PDT for Pacific Daylight Time, and MST7MDT for Mountain Daylight Time) or, TZ can be removed from JHTTPD and set in a system logon UDC. For more information about setting the timezone value, please read the POSIX help file.

  shell/iX> man timezone

Prior to Apache 1.3.14, JHTTPD was an MPE/iX fixed-ASCII file. Starting with Apache 1.3.14, JHTTPD is a bytestream file. Note also that the file mask is set to 007 in JHTTPD. This means that files created by Apache will lack permissions for "other". This feature tightens security so that Apache-created files are accessible only within the APACHE account.

The JHTTPD file does not come with a password. If desired, the JOBSECURITY command can be used to provide password protection without adding your password to the JHTTPD file.

Start Apache


Start the HTTPD web server program by streaming the JHTTPD job file. This can be done from either the CI or the POSIX shell:

  :STREAM JHTTPD.PUB.APACHE

or

  :XEQ SH.HPBIN.SYS -L
  shell/iX>callci "stream jhttpd.pub.apache"

Verify that Apache is Running


There are a number of ways to verify if the Apache web server is running or, if it is not, to isolate how far the startup process has progressed.

After streaming the JHTTPD file, use :SHOWJOB to view the running job:

  JOBNUM STATE IPRI JIN JLIST INTRODUCED  JOB NAME
  #J16   EXEC  10S      LP    TUE 10:27A  JHTTPD,WWW.APACHE

Another method used to check server status, is executing :SHOWPROC at the CI or using ps from the POSIX shell. Here the parent HTTPD process is PIN 76, the child of SH.HPBIN.SYS.

  :SHOWPROC; job=httpd,www.apache
  QPRI  CPUTIME   STATE JOBNUM PIN  (PROGRAM) STEP
  D202  0:00.182  WAIT   J321   75  :XEQ sh.hpbin.sys "-c 'umask 007;./HTTPD -$
  D202  0:00.202  WAIT   J321    65   (SH.HPBIN.SYS) -c 'umask 007;./HTTPD -f $
  D202  0:03.313  WAIT   J321     76   (HTTPD.PUB.APACHE)
  D202  0:00.053  WAIT   J321       91   (HTTPD.PUB.APACHE)
  D202  0:00.050  WAIT   J321       79   (HTTPD.PUB.APACHE)
  D202  0:00.051  WAIT   J321       43   (HTTPD.PUB.APACHE)
  D202  0:00.049  WAIT   J321       95   (HTTPD.PUB.APACHE)
  D202  0:00.048  WAIT   J321       58   (HTTPD.PUB.APACHE)

Using ps to display process status shows PID 19660876 as the parent HTTPD process. It is the child of PID 36896833, SH.HPBIN.SYS.

  shell/iX> ps -ef | grep HTTPD
  WWW.APACHE   15466539   19660876  0   Dec 31 ldev10   0:00 HTTPD.PUB.APACHE
  WWW.APACHE   11010106   19660876  0   Dec 31 ldev10   0:00 HTTPD.PUB.APACHE
  WWW.APACHE   36896833   15204427  0   Dec 31 ldev10   0:00 SH.HPBIN.SYS
    info=-c 'umask 007;./HTTPD
  WWW.APACHE   19660876   36896833  0   Dec 31 ldev10   0:03 HTTPD.PUB.APACHE
  WWW.APACHE   23527503   19660876  0   Dec 31 ldev10   0:00 HTTPD.PUB.APACHE
  WWW.APACHE   23396443   19660876  0   Dec 31 ldev10   0:00 HTTPD.PUB.APACHE
  WWW.APACHE   24510559   19660876  0   Dec 31 ldev10   0:00 HTTPD.PUB.APACHE

After the HTTPD program is running, verify that files in the directory tree are accessible:
  • Server home page, http://yourserver.com. This brings up the default Apache home page /APACHE/PUB/htdocs/index.html.

  • MGR.APACHE home page, http://yourserver.com/~MGR.APACHE. This brings up the page /APACHE/PUB/public_html/index.html. To create a new default page for MGR.APACHE, copy the sample file and edit it:


  shell/iX> cd /APACHE/PUB/public_html
  shell/iX> cp /APACHE/VUUFF/public_html/index.html.sample index.html

  • The Apache online documentation manual:

    http://yourserver.com/manual

  • The cgi test script, test-cgi. This script first needs to have execute permission before it can run:

    
      shell/iX>cd /APACHE/PUB/cgi-bin
      shell/iX>cp /APACHE/VUUFF/cgi-bin/test-cgi test-cgi
      shell/iX>chmod +x test-cgi
    
    
    Execute the script:

    http://yourserver.com/cgi-bin/test-cgi

Troubleshooting Apache Setup Problems


If unsuccessful in starting the HTTPD program, get more information about the problem by trying one or more of these troubleshooting techniques:
  1. Look at the output of the JHTTPD spoolfile.

  2. Check the messages in the /APACHE/PUB/logs/error_log file.

  3. Verify the syntax of the httpd.conf file. This catches many, but not all, syntax problems in the httpd.conf file.

    :run HTTPD.PUB.APACHE:info="-t"

    or

    
      shell/iX> /APACHE/PUB/HTTPD -t
    
    
  4. Access Apache's port across the network (port 80 if the port directive set in the httpd.conf file has not been modified).

If telnet to Apache's port fails, then the problem is not with the web server, since the connection is not yet reaching the HP e3000 box. A successful telnet connection should look something like:

  $telnet hostname 80  (from a UNIX machine)
  Trying...
  Connected to hostname.hp.com.
  Escape character is '^]'.
  GET / HTTP/1.0<RETURN><RETURN>   <--- user input

or

  :xeq telnet.arpa.sys  (from an MPE machine)
  Telnet Client [A6000000]     (C) Hewlett-Packard Co. 1994
  telnet> toggle crlf
  Will send carriage returns as telnet <CR><LF>.
  telnet> open hostname 80
  Trying...
  Connected to hostname.hp.com.
  Escape character is '^]'.
  Failed to turn on single echo: 68.
  GET / HTTP/1.0<RETURN><RETURN>   <--- user input

The telnet connection should successfully read the /APACHE/PUB/htdocs/index.html file.

Stopping Apache


Apache can be stopped by issuing an :ABORTJOB or kill. Kill can be issued by users WWW.APACHE, MGR.APACHE, and MANAGER.SYS. Using kill (which defaults to kill -TERM) is the preferred method for stopping Apache since it uses Apache's internal routines to clean up open resources. Using :ABORTJOB will result in leaked SVIPC semaphores. The CI command file IPCS.HPBIN.SYS can be used to display SVIPC semaphores and the CI command file IPCRM.HPBIN.SYS can be used to free leaked semaphores.

To stop Apache from the POSIX's shell:

  shell/iX>kill `cat /APACHE/PUB/logs/httpd.pid`

To stop Apache from the CI:

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS "-c 'kill `cat /APACHE/PUB/logs/httpd.pid`'"

If kill cannot be used, Apache can be stopped with :ABORTJOB as a last resort from either the CI or POSIX shell:

  :ABORTJOB JHTTPD,WWW.APACHE

or

  :XEQ SH.HPBIN.SYS -L
  shell/iX>callci "abortjob jhttp,www.apache"

Restarting Apache


Apache can be restarted by issuing a kill -HUP. A restart will cause Apache to reread its configuration files without having to stop and restream the Apache job stream file. Restart is useful for making configuration changes without disrupting web users. After a restart, Apache continues running with the new configuration settings.

To restart Apache:

  shell/iX>kill -HUP `cat /APACHE/PUB/logs/httpd.pid`

or

  :XEQ SH.HPBIN.SYS "-c 'kill -HUP `cat /APACHE/PUB/logs/httpd.pid`'"

Stopping or restarting Apache using kill may cause the error_log to contain numerous warning messages about the child processes not exiting promptly.

Error Logging


Apache error logging is useful when trying to start Apache as well as for monitoring a running web server. Apache will log errors into a log file called error_log by default. This log file resides in the /APACHE/PUB/logs directory.

The number of messages logged in the error log is set by the LogLevel directive in the httpd.conf file. Possible values for LogLevel (by increasing significance) are debug, info, notice, warn, error, crit, alert, emerg. When a particular level is specified, messages from all other levels of higher significance are reported as well. For example, when LogLevel is "info", then messages with log levels of notice, warn and up to emerg are also posted.

By default, the level is set to warn. Using a level of at least crit is recommended.

Managing Log Files


Apache log files can grow quite large, especially for high traffic sites. It's best to monitor the size of the log files and periodically purge or archive them. Purge or rename log files only while Apache is stopped or after restarting Apache. This is necessary because Apache continues to write to these files while it is running:

  :HELLO MGR.APACHE,PUB
  :XEQ SH.HPBIN.SYS -L
  shell/iX> cd logs
  shell/iX> mv access_log access_log.old (Apache is writing to access_log.old)
  shell/iX> mv error_log error_log.old (Apache is writing to error_log.old)
  shell/iX> kill -HUP 'cat httpd.pid'

After executing the kill -HUP, Apache is no longer writing to the *.old files. Apache is now writing to a new error_log and a new access_log and the *.old files can be purged or archived.

Adding Documents


There are several ways to add content to the Apache web server:
  • Add files or directories beneath the DocumentRoot, /APACHE/PUB/htdocs.

  • Use the Alias directive in httpd.conf to name a different document location outside of the DocumentRoot.

  • Use symbolic links from the files and directories beneath the DocumentRoot to point outside the DocumentRoot. This requires Options FollowSymLinks be set in httpd.conf.

  • Create a user directory reference. For USER.ACCOUNT, create directory /ACCOUNT/GROUP/public_html where GROUP is the home group of USER.ACCOUNT. File /ACCOUNT/GROUP/public_html/foo.html would be accessed by http://yourserver.com/~USER.ACCOUNT/foo.html.

All files and directories must be readable by WWW.APACHE, the runtime user for the Apache web server on MPE/iX. Directories must also have traverse directory permission (TD) for all the directories in the path to the file Apache is accessing. In the POSIX shell, traverse directory permission is shown as execute (X) permission for the directory. For example, to add a new directory call "newdir" under DocumentRoot:

  shell/iX> cd /APACHE/PUB/htdocs
  shell/iX> mkdir newdir
  shell/iX> chown MGR.APACHE:APACHE newdir
  shell/iX> chmod 750 newdir

To check if a file is accessible to the Apache web server, logon as the Apache runtime user, WWW.APACHE and try to access the file.

Working with Dynamic Shared Objects (DSOs)


DSOs are add-on modules that extend the functionality of Apache. These modules are self-contained code that can provide a wide-range of additional Apache capabilities such as custom authentication and authorization, custom logging, or creating new configuration directives.

Users can create their own Apache modules or use those written by others. For instance, the Apache Module Registry (http://modules.apache.org/) is a web site with downloadable Apache modules. Some of these modules are freely available while others have various license restrictions.

DSOs on MPE/iX can utilize Apache's full Application Programming Interface (API) as well as Apache's full Extended Application Programming Interface (EAPI).

A DSO is an Apache module with the same structure as the modules compiled into the Apache binary. But instead of being statically linked into the Apache program, the DSO module is created as a shared library (NMXL). DSOs are loaded at Apache startup into Apache's process space.

No recompilation of Apache is necessary to use DSOs. However, DSOs require a DSO-enabled Apache. Apache for MPE/iX is enabled for DSOs starting with Apache 1.3.9 (A.01.00).

Using DSO modules keeps Apache memory usage low by running an Apache binary with core features only and adding additional features with DSOs. DSOs also provide flexibility. An installation can pick and choose which features to include in their web server.

Creating Apache Modules


DSOs can be written in either the C programming language or in the Perl scripting language. DSOs written in C must be compiled on MPE/iX. Those written in Perl require a Perl interpreter to be embedded into Apache. This embedded Perl interpreter is provided by the mod_perl module. Mod_perl is part of the HP WebWise MPE/iX Secure Web Server product, version 2 or later, but is not part of standard Apache on MPE/iX. Since Perl modules cannot currently be used with standard Apache, this manual describes only how to create Apache DSOs in C.

Two ways that Apache module's can be created are:
  1. From a template, such as mod_example.c, or from an existing module.

  2. With the apxs utility.

A sample module, mod_hw, will be used to illustrate these two methods for creating a DSO module in C. The code for mod_hw is listed in the section "Sample Module Code (mod_hw)" and the mod_hw structure is shown in Figure 9-1 "Sample Module (mod_hw)".

Figure 9-1 Sample Module (mod_hw)

[Sample Module (mod_hw)]

The mod_hw consists of two source files, mod_hw.c and hw.c. The file mod_hw.c contains the module structure and makes an external function call to pow() in the math library (/lib/libm). The mod_hw.c also makes an external function call to helloworld(), defined in hw.c. The output of mod_hw prints "Hello World" and also prints the result of raising 12 to the power of 2.

This module demonstrates how to build a DSO that calls external functions. Using mod_hw as an example, you will see how to compile and link an Apache module that calls an external function from an object file and calls an external function from a system library.

Note that modules are named mod_xxx.so by convention. To follow this convention, the sample module is called mod_hw.so.

Tools


There are a number of options available when choosing tools to build an Apache module for MPE/iX. Some of these tools are open source tools from the GNU Project, a provider of free software. The GNU tools are used on many operating system platforms for development of open source code, including MPE/iX.

Module compilations on MPE/iX can be done with the GNU C compiler, gcc, or with the MPE/iX POSIX compiler, c89. HP recommends using gcc for compiling open source modules since most open source code is designed for compilation by gcc. For example, Apache for MPE/iX is compiled with gcc. Use c89 when calling MPE/iX intrinsics or using long pointers.

When using a Makefile to build a module, it can be executed with GNU make or with the MPE/iX POSIX make. GNU make is recommended for executing a Makefile created by apxs since this file is generated by open source code. The GNU tools' installation script installs GNU make in /usr/local/bin/make. MPE/iX make resides in /bin/make.

Modules can be lined with GNU ld or with the MPE/iX LinkEditor. HP recommends using LinkEditor for linking Apache modules since the LinkEditor creates shared libraries that work well with dynamic loading.

Make, gcc, and ld are part of the GNU tools which are downloadable from http://jazz.external.hp.com/src/gnu/gnuframe.html. Support contracts for gcc are available from http://www.gccsupport.html. LinkEditor, c89 and /bin/make are supported by HP.

The Apache C header files are required when compiling an Apache module. These header files are distributed with the Apache product and reside in /APACHE/PUB/include.

Module Creation Using a Template


Any existing Apache module can be used as a template for a new module. Mod_example.c is distributed with Apache in /APACHE/PUB/libexec and makes a useful template for a simple module. When compiled and linked as the shared library (NMXL) mod_example.so, this module is a fully working DSO. Libexec/mod_example.so has already been pre-built.

For a more functional module, try a different module as your template. For instance, to create a new module that does authentication, starting with one of Apache's authentication modules may be more appropriate. If you want to create a module that has its own configuration directives, start with another module that already does this.

To create the module file "mod_hw.c" from file "mod_example.c", log on as MGR.APACHE so that the file is created with the right ownership:

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS -L
  shell/iX> mkdir hw
  shell/iX> cd hw
  shell/iX> cp /APACHE/PUB/libexec/mod_example.c mod_hw.c

Change all references inside mod_hw.c from mod_example, example_module, example_handler, etc. to mod_hw, hw_module, hw_handler, etc., and modify/add any other code, as needed. Creating a separate directory for the module, such as hw, separates it from other modules under development.

To compile a module, certain compile options must be specified and the Apache C header files must also be included. Below, gcc creates two object files, hw.o and mod_hw.o, using the necessary options and include files. Use the -c option for compilation:

  shell/iX> gcc -DMPE -D_POSIX_SOURCE -D_SOCKET_SOURCE
  -DNO_DBM_REWRITEMAP -DUSE_HSREGEX -DEAPI -DSHARED_MODULE
  -I/APACHE/PUB/include -c mod_hw.c hw.c

Next, link the module. The link steps will be different when calling external functions that reside in archive or shared libraries. Other examples of linking are shown later.

To link, the MPE/iX LinkEditor can be called from the CI or the POSIX shell:

:linkedit

or

  shell/iX> callci linkeditLinkEd> buildxl xl=./mod_hw.so;limit=5
  LinkEd> addxl from=./mod_hw.o,./hw.o;to=./mod_hw.so;
  rl=/lib/libm.a,/lib/libc.a;merge;share
  1 OBJECT FILE HAS BEEN ADDED.

The "rl=" option is used to specify which archive libraries are used to resolve external function calls. The math library (/lib/libm.a) is specified here to resolve pow() in mod_hw.o. /lib/libc.a is not actually needed by the sample code. But it is a good practice to always specify libc since most modules and other libraries are likely to need functions from this library. If libc is not specified explicitly as shown here, the MPE/iX C library will be used by default (LIBC.LIB.SYS). Since Apache is built with libc, we recommend explicitly specifying /lib/libc instead of defaulting to LIBC.LIB.SYS. /lib/libc and LIBC.LIB.SYS are not identical. The order of the libraries listed by "rl=" is important and libc should always be specified last. The merge directive is necessary when functions are called across object boundaries such as mod_hw.o calling helloworld() in hw.o. The share option is needed when global data is shared between multiple object files. The share option is not actually needed by the sample code.

The compile and link steps can be put in a Makefile to facilitate multiple builds of a module. As an example, refer to the section "Modified APXS Makefile (mod_hw)".

Mod_hw.so is now ready to be configured into Apache. To do this, refer to the section "Configuring Apache Modules".

Module Creation Using the APXS Utility


Modules can also be created using the bin/apxs utility "Apache eXtenSion" tool. Details on using apxs are found in the apx manual page, http://www.apache.org/docs/programs/apxs.html. Apxs is a Perl script and requires a working Perl interpreter on the HP e3000. The Perl interpreter is not distributed as part of FOS but is available as freeware via http://jazz.external.hp.com. To prepare a system for running apxs:
  • Install the GNU tools.

  • Install the Perl interpreter.

  • Set up a Perl symbolic link.


  shell/iX> ln -s /PERL/PUB/PERL /usr/local/bin/perl

Apxs has a number of options. The -g and -n options will create a module skeleton with a corresponding Makefile. Log on as MGR.APACHE in order to execute apxs and to create a module with MGR.APACHE as the owner.

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS -L
  shell/iX> ./bin/apxs -g -n hw
  Creating [DIR]  hw
  Creating [FILE] hw/Makefile
  Creating [FILE] hw/mod_hw.c
  shell/iX> cd hw
  shell/iX> ls
  Makefile   mod_hw.c

Apxs -g -n will create directory "hw" with the module source file mod_hw.c and its Makefile. This directory is where the module is developed. Note that the mod_hw.c file created here is not the same as the sample module code. To continue following this example, use the code listings given for mod_hw.c and hw.c.

Makefile can be used for compiling and linking the module. The default Makefile created here by apxs uses apxs for compiling and linking. We recommend changing this to use gcc and LinkEditor as shown in the section "Modified APXS Makefile (mod_hw)". The modified Makefile still calls apxs for getting the correct compile options and include files but does not use apxs for compiling and linking.

Makefile can easily be modified for customization. For the sample module, mod_hw, the additional source file, hw.c, was added to Makefile. Using a Makefile is a convenient and flexible way to build modules.

Here is the output from executing mod_hw's modified apxs Makefile:

  shell/iX> cd /APACHER/PUB/hw
  shell/iX> makegcc -o mod_hw.o `/APACHE/PUB/bin/apxs -q CFLAGS` \
    -I`/APACHE/PUB/bin/apxs -q INCLUDEDIR` -c mod_hw.c
  gcc -o hw.o `/APACHE/PUB/bin/apxs -q CFLAGS`  -I`/APACHE/PUB/bin/apxs -q INCLUDEDIR` \
    -c hw.c
  callci "linkedit 'buildxl xl=./mod_hw.so;limit=5'"
  HP Link Editor/iX (HP30315A.06.15) Copyright Hewlett-Packard Co 1986

  LinkEd> buildxl xl=./mod_hw.so;limit=5

  LinkEd> addxl from=./mod_hw.o,./hw.o;to=./mod_hw.so; rl=/lib/libm.a,/lib/libc.a
  ;merge;share
  1 OBJECT FILE HAS BEEN ADDED.

Linking Libraries into a DSO


When a DSO requires external library functions, as does mod_hw, these can be resolved using either archive libraries or shared libraries. With archive libraries, external calls are resolved at link time and the functions are incorporated into your DSO. With shared libraries, external calls are resolved at run time. At run time, the loader searches the shared libraries for these external functions.

This section discusses the linking of a module. Linking is independent of the method used to create and compile the module code.

Archive libraries


Archive libraries may be either custom archive libraries (built by others) or system archive libraries. System archive libraries are ".a" files residing in /lib and /usr/lib.

The following shows how to build hw.c as an archive library then link it into mod_hw.so:

  shell/iX> cd /APACHE/PUB/hw
  shell/iX> gcc -c -DMPE -D_POSIX_SOURCE -D_SOCKET_SOURCE -DNO_DBM_REWRITEMAP
  -DUSE_HSREGEX -DEAPI -DSHARED_MODULE -I/APACHE/PUB/include hw.c
  shell/iX> ar -rv hw.a hw.o
  ar: creating hw.a
  a - /APACHE/PUB/hw/hw.o
  1 OBJECT FILE HAS BEEN ADDED.
  
  shell/iX> callci linkedit
  HP Link Editor/iX (HP30315A.06.15) Copyright Hewlett-Packard Co 1986
  LinkEd> buildxl xl=./mod_hw.so;limit=5
  LinkEd> addxl from=./mod_hw.o;to=./mod_hw.so;merge;share;rl=./hw.a,/lib/libm.a,
  /lib/libc.a
  1 OBJECT FILE HAS BEEN ADDED.

Shared libraries


Shared libraries (XLs) can also be used for resolving external function calls from a DSO. One method is to relink the Apache program with an XL list of the required shared libraries and to copy each shared library into MPE/iX namespace. Another method is to link a DSO using dependent libraries the (altxl option to the LinkEditor) and to copy each shared library into MPE/iX namespace. Either way, all shared libraries must reside in an MPE/iX group and account and must follow the MPE/iX naming conventions. This is necessary because Apache is a Privileged Mode (PM) program.

Symbolic links from the MPE/iX namespace to a shared library in the HFS namespace will not satisfy the PM capability constraint. Each shared library must actually reside in MPE/iX namespace. The following commands show how to copy the libm and libc system shared libraries into MPE/iX namespace and how to use the altprog option to LinkEditor to add these shared libraries to the Apache program file:

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS -L
  shell/iX> cp /lib/libm.sl XLM
  shell/iX> cp /lib/libc.sl XLC
  shell/iX> callci linkedit
  LinkEd> buildxl xl=./hw/mod_hw.so;limit=10
  LinkEd> addxl from=./hw/mod_hw.o,./hw/hw.o;to=./hw/mod_hw.so;merge;share
  LinkEd> altprog ./HTTPD;cap=ia,ba,ph,pm;xl=XLM,XLC

When using system libraries as XLs, such as libm.sl and libc.sl, remember to recopy these libraries after a system update in order to get their new versions. To verify that HTTPD has been successfully relinked with your NMXL(s):

  LinkEd> listprog ./HTTPD

  PROGRAM        : ./HTTPD
  XL LIST        : XLM XLC
  CAPABILITIES   : BA, IA, PM, PH

Here is a POSIX script that shows how libraries might be set up programmatically. It uses hw.o as the archive library, hw.a:

  shell/iX> cat xlbuild.sh
  #!/bin/sh
  #
  # set the location of Apache
  AP=/APACHE/PUB
  #
  # create the old libraries
  rm -f ${AP}/XLC ${AP}/XLM ${AP}/XLHW
  #
  # copy the latest versions
  cp /lib/libc.sl ${AP}/XLC
  cp /lib/libm.sl ${AP}/XLM
  #
  #create a custom XL
  callci "xeq linkedit.pub.sys 'buildxl xl=${AP}/XLHW'"
  callci "xeq linkedit.pub.sys 'addxl from=${AP}/hw/hw.a;to=${AP}/XLHW;share;merge'"
  #
  # remove fragmentation and minimize the internal tables
  callci "xeq linkedit.pub.sys 'cleanxl ${AP}/XLHW;compact'"
  #
  # Relink Apache with the new NMXL list
  callci "xeq linkedit.pub.sys \
    'altprog ${AP}/HTTPD;cap=ia,ba,ph,pm;xl=\"${AP}/XLHW,${AP}/XLM,${AP}/XLC\"'"

Configuring Apache Modules


Once a DSO has been compiled and linked, it needs to be configured. DSOs can be configured manually or they can be configured with apxs. Configuration consists of copying the DSO module to a known location then updating httpd.conf to find and execute the DSO.

Manual Configuration

By convention, DSOs written in C reside in /APACHE/PUB/libexec. After copying a DSO to this location, the AddModule and LoadModule directives must be added to httpd.conf. An example of where to place AddModule and LoadModule is shown in the httpd.conf file for mod_example. Additional directives may be necessary to configure a DSO's handler, depending on what the DSO is trying to accomplish.

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS -L
  shell/iX> cp hw/mod_hw.so libexec/mod_hw.so
  shell/iX> vi conf/httpd.conf
  ...
  # Note: The order is whch modules are loaded is important.
  # Don't change the order below without expert advice
  #
  # Example:
  # LoadModule foo_module libexec/mod_foo.so
  # LoadModule example_module libexec/mod_example.so
  LoadModule hw_module libexec/mod_hw.so
  ...
  AddModule mod_cern_meta.c
  AddModule mod_expires.c
  AddModule mod_headers.c
  AddModule mod_usertrack.c
  #AddModule mod_example.c
  AddModule mod_jw.c
  AddModule mod_unique_id.c
  AddModule mod_so.c
  AddModule mod_setenvif.c
  ...

Mod_hw includes a handler so the following additional directives are added to httpd.conf:

  ...
  <IfModule mod_hw.c>
    <Location /hw>
      SetHandler hw-handler
    </Location>
  </IfModule>
  ...

The LoadModule directive takes two arguments. The first is the name of the module to load. This is the module's structure name taken from the source file mod_hw.c. The second argument is the path to the shared object file to load. The path can be relative to the server root (/APACHE/PUB), as shown here, or it can be an absolute path.

APXS Configuration

To use apxs for configuration, use the install option of Makefile. This will copy a module into libexec and automatically update httpd.conf with the AddModule and LoadModule directives. Additional configuration changes may be necessary (such as manually configuring the hw-handler as shown in the manual configuration) depending on what the module does:

  :HELLO MGR.APACHE
  :XEQ SH.HPBIN.SYS -L
  shell/iX> cd hw
  shell/iX> make install
  /APACHE/PUB/bin/apxs -i -a -n 'hw' mod_hw.so
  cp mod_hw.so /APACHE/PUB/libexec/mod_hw.so
  chmod 755 /APACHE/PUB/libexec/mod_hw.so
  [activating module `hw' in /APACHE/PUB/conf/httpd.conf]

Testing a DSO


After configuration or at any time after modifying a DSO, restart Apache in order to load the module:

  shell/iX> cd /APACHE/PUB/logs
  shell/iX> kill -HUP `cat ./httpd.pid`

or

  kill -TERM 'cat httpd.pid`;callci stream ../JHTTPD

To execute the mod_hw DSO, access the <Location> specified in the httpd.conf file. A DSO may be executed in a different way, depending on the DSO's functionality:

http://yourserver.com/hw

The output of the mod_hw module prints "Hello World!" followed by the result of raising the number 12 to the power of 2. The following is the output seen in a browser:

  Hello World!
  The result of 12.00**2.00 is 144.00




Feature Set


Sample Module Code (mod_hw)